This question has been asked before, but this is a more specific instance.
In the Ruby on Rails "Getting Started" [ http://guides.rubyonrails.org/getting_started.html ] web page, they're teaching you how to make a simple blog. I'm following most of it, but I do not get where this :article_id key value is coming from:
@article = Article.find(params[:article_id])
...some other stuff...
routes.rb defines routes, the matched route may have variable segments in it, and the variable segments are made available to you via the
params hash in your controller.
If you're using
params[:article_id], the route that lead you to that action would have contained something like:
params will also contain any values passed along via the query string or form data, but as far as looking up records by their ID, the ID is usually a component of the URL.
Is the underscore an indicator to the class the id belongs to?
No, it's simply part of the name.
If it is the latter case, how would you know the key value to use?
Because you define the key to use in your routes file.