Params not being passed to method in Rails 3.0.3
I have another very puzzling question that has cropped up after my upgrade from Rails 2.3.4 to Rails 3.0.3.
I am calling a 'show' controller method with the following URL:
/verse/10
and I see this in the terminal
Started GET "/verse/10" for 127.0.0.1 at 2011-01-27 16:17:58 -0800
Processing by VersesController#show as HTML
* Searching for verse with ID:Rendered verses/show.html.erb within layouts/application (76.6ms)
Completed 200 OK in 1006ms (Views: 125.4ms | ActiveRecord: 9.8ms)
The verse show method is very simple:
def show
logger.debug("*** Searching for verse with ID: #{params[:id]}")
@vs = Verse.find(params[:id])
end
The route is defined as follows:
match '/verse/:id', :to => 'verses#show', :as => 'verse'
The problem: the parameter, ID, which in this case is '10', is not being passed in to the controller method and so a 404 is being thrown because params[:id] is nil.
The output from "rake routes | grep verse" is as follows:
verse /verse/:id(.:format) {:controller=>"verses", :action=>"show"}
I've spent ages on this but feel as though I'm missing something very obvious.
Here is the full rake routes output:
login /login(.:format) {:controller=>"sessions", :action=>"new"}
logout /logout(.:format) {:controller=>"sessions", :action=>"destroy"}
register /register(.:format) {:controller=>"users", :action=>"create"}
signup /signup(.:format) {:controller=>"users", :action=>"new"}
activate /activate/:activation_code(.:format) {:activation_code=>nil, :controller=>"users", :action=>"activate"}
forgot_password /forgot_password(.:format) {:controller=>"passwords", :action=>"new"}
change_password /change_password/:reset_code(.:format) {:controller=>"passwords", :action=>"reset"}
open_id_complete GET /opensession(.:format) {:controller=>"sessions", :action=>"create"}
open_id_create GET /opencreate(.:format) {:controller=>"users", :action=>"create"}
users GET /users(.:format) {:action=>"index", :controller=>"users"}
POST /users(.:format) {:action=>"create", :controller=>"users"}
new_user GET /users/new(.:format) {:action=>"new", :controller=>"users"}
edit_user GET /users/:id/edit(.:format) {:action=>"edit", :controller=>"users"}
user GET /users/:id(.:format) {:action=>"show", :controller=>"users"}
PUT /users/:id(.:format) {:action=>"update", :controller=>"users"}
DELETE /users/:id(.:format) {:action=>"destroy", :controller=>"users"}
passwords GET /passwords(.:format) {:action=>"index", :controller=>"passwords"}
POST /passwords(.:format) {:action=>"create", :controller=>"passwords"}
new_password GET /passwords/new(.:format) {:action=>"new", :controller=>"passwords"}
edit_password GET /passwords/:id/edit(.:format) {:action=>"edit", :controller=>"passwords"}
password GET /passwords/:id(.:format) {:action=>"show", :controller=>"passwords"}
PUT /passwords/:id(.:format) {:action=>"update", :controller=>"passwords"}
DELETE /passwords/:id(.:format) {:action=>"destroy", :controller=>"passwords"}
session POST /session(.:format) {:action=>开发者_运维知识库;"create", :controller=>"sessions"}
new_session GET /session/new(.:format) {:action=>"new", :controller=>"sessions"}
edit_session GET /session/edit(.:format) {:action=>"edit", :controller=>"sessions"}
GET /session(.:format) {:action=>"show", :controller=>"sessions"}
PUT /session(.:format) {:action=>"update", :controller=>"sessions"}
DELETE /session(.:format) {:action=>"destroy", :controller=>"sessions"}
quests GET /quests(.:format) {:action=>"index", :controller=>"quests"}
POST /quests(.:format) {:action=>"create", :controller=>"quests"}
new_quest GET /quests/new(.:format) {:action=>"new", :controller=>"quests"}
edit_quest GET /quests/:id/edit(.:format) {:action=>"edit", :controller=>"quests"}
quest GET /quests/:id(.:format) {:action=>"show", :controller=>"quests"}
PUT /quests/:id(.:format) {:action=>"update", :controller=>"quests"}
DELETE /quests/:id(.:format) {:action=>"destroy", :controller=>"quests"}
index /home(.:format) {:controller=>"verses", :action=>"index"}
starter_pack /starter_pack(.:format) {:controller=>"verses", :action=>"starter_pack"}
*verse /verse/:id(.:format) {:controller=>"verses", :action=>"show"}*
tag_cloud /tag_cloud(.:format) {:controller=>"verses", :action=>"tag_cloud"}
show_user_info /show_user_info(.:format) {:controller=>"admin", :action=>"show_user_info"}
show_tags /show_tags(.:format) {:controller=>"admin", :action=>"show_tags"}
contact /contact(.:format) {:controller=>"info", :action=>"contact"}
faq /faq(.:format) {:controller=>"info", :action=>"faq"}
tutorial /tutorial(.:format) {:controller=>"info", :action=>"tutorial"}
volunteer /volunteer(.:format) {:controller=>"info", :action=>"volunteer"}
leaderboard /leaderboard(.:format) {:controller=>"info", :action=>"leaderboard"}
stateboard /stateboard(.:format) {:controller=>"info", :action=>"stateboard"}
countryboard /countryboard(.:format) {:controller=>"info", :action=>"countryboard"}
referralboard /referralboard(.:format) {:controller=>"info", :action=>"referralboard"}
news /news(.:format) {:controller=>"info", :action=>"news"}
update_profile /update_profile(.:format) {:controller=>"profile", :action=>"update_profile"}
referrals /referrals/:id(.:format) {:controller=>"profile", :action=>"referrals"}
unsubscribe /unsubscribe/*email(.:format) {:controller=>"profile", :action=>"unsubscribe"}
edit_tag /edit_tag/:id(.:format) {:controller=>"tag", :action=>"edit_tag"}
tweets /tweets(.:format) {:controller=>"tweets", :action=>"index"}
load_progress /load_progress/:user(.:format) {:controller=>"chart", :action=>"load_progress"}
root /(.:format) {:controller=>"sessions", :action=>"new"}
home /home(.:format) {:controller=>"sessions", :action=>"new"}
/:controller(/:action(/:id))(.:format)
If you have the open_id_authentication
plugin installed, that is likely interfering with your routes.
精彩评论