I need an explanation about how create new path on rails 3. I want this link for example
link_to "eat chocolate", eat_chocolate_user_path(user)
be equals to
link_to "eat chocolate", :controller => 'user', :action=>'eat_chocolate', :id=> user
I read many guides about it, including routing of railsguide. But i still do not know how it exactly work.
add the following line to your routes.rb file.
match 'user/eat_chocolate/:id' => 'user#eat_chocolate', :as => :eat_chocolate_user
Look up named routes for more info.
In some cases it will be better to use GET
.
Using match
will accept ALL http verbs GET
PUT
POST
DELETE
meaning that somebody could potentially mis-use your application. If all you're doing is showing something in a #show action, you should use this instead
get 'user/eat_chocolate/:id' => 'user#eat_chocolate', :as => :eat_chocolate_user
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With