ruby on rails adding new route
Posted
by ohana
on Stack Overflow
See other posts from Stack Overflow
or by ohana
Published on 2010-04-26T21:00:34Z
Indexed on
2010/04/26
21:03 UTC
Read the original article
Hit count: 290
ruby-on-rails
i have an RoR application Log, which similar to the book store app, my logs_controller has all default action: index, show, update, create, delete..
now i need to add new action :toCSV, i defined it in logs_controller, and add new route in the config/routes as:
map.resources :logs, :collection => { :toCSV => :get }.
from irb, i checked the routes and see the new routes added already:
>> rs = ActionController::Routing::Routes >> puts rs.routes GET /logs/toCSV(.:format)? {:controller=>"logs", :action=>"toCSV"}
then ran ‘rake routes’ command in shell, it returned:
toCSV_logs GET /logs/toCSV(.:format) {:controller=>"logs", :action=>"toCSV"}
everything seems working. finally in my views code, i added the following:
link_to 'Export to CSV', toCSV_logs_path
when access it in the brower 'http://localhost:3000/logs/toCSV', it complained: Couldn't find Log with ID=toCSV
i checked in script/server, and saw this one:
ActiveRecord::RecordNotFound (Couldn't find Log with ID=toCSV): app/controllers/logs_controller.rb:290:in `show'
seems when i click that link, it direct it to the action 'show' instead of 'toCSV', thus it took 'toCSV' as an id...anyone know why would this happen? and to fix it? Thanks...
© Stack Overflow or respective owner