开发者

rails 3 : How to create a path?

开发者 https://www.devze.com 2023-03-21 09:12 出处:网络
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)

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 ho开发者_开发技巧w 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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号