RoR: I'm having trouble doing a simple link to an action
I am trying to link to action addData in开发者_C百科 the entries controller. I have constructed the link like this:
<%= link_to image_tag (w.link, :border =>0) ,:controller => :entries, :action => :addData %>
but when I click on the link, I get this error:
Couldn't find Entry with ID=addData
I'm pretty sure this is because I have a restful design. Is there a way around this problem? Thanks for reading.
Rails has migrated wholly to a RESTful design. This means that in order to use non standard actions you have to add them to your resources in config/routes.rb
.
If they operate on all resources you add them to the hash :collection => {:addData => :post}
In case you have one operating on a single resource with an id use :member
.
To some it up for you.
map.resources :entries, :collection => {:addData => :post}
To use the old style of mapping any action to any controller you can add the following two lines to your config/routes.rb
map.connect ':controller/:action/:id.:format'
map.connect ':controller/:action/:id'
Have you defined the route properly for this action addData? By the way try this :
<%= link_to image_tag (w.link, :border =>0) ,{:controller => :entries, :action => :addData} %>
精彩评论