我有一个Rails 3.1应用程序,我只是有一些奇怪的行为。
我有两条路线声明如下:
# OLD METHOD
get 'accept_terms', :to => "users_terms#show"
put 'accept_terms', :to => "users_terms#accept'"
正在运行rake routes
包括以下内容:
# accept_terms
# GET /accept_terms(.:format) {:action=>"show", :controller=>"users_terms"}
# PUT /accept_terms(.:format) {:action=>"accept'", :controller=>"users_terms"}
GET
工作正常,但PUT
产生了此错误:
AbstractController::ActionNotFound (The action 'accept'' could not be found for UsersTermsController):
我确认该操作确实存在于该控制器上。
在修补问题的同时,我将路线声明更改为:
get 'accept_terms', :controller => 'users_terms', :action => 'show'
put 'accept_terms', :controller => 'users_terms', :action => 'accept'
正在运行rake routes
:
# accept_terms
# GET /accept_terms(.:format) {:controller=>"users_terms", :action=>"show"}
# PUT /accept_terms(.:format) {:controller=>"users_terms", :action=>"accept"}
有了这个,GET
和PUT
都运行良好。
:to => "controller#action
与:controller => 'controllerName', :action => 'actionName'
不一样吗?
我在制作的路线中看到的唯一区别是:action
和:controller
...
答案 0 :(得分:2)
在旧方法中,您使用单引号和双引号结束users_terms#accept
。