2011-02-09 133 views
1

解决了其他problem with routes后,现在我有另一个。Rails 3路由问题

我在routes.rb中这条路线:

 

match "user/create_new_password/:reset_password_key" =>"users#create_new_password", :via=>[:post, :get], :as=>:create_new_password 
 

我可以测试它在我的功能测试是这样的:

 

test "should create new password " do 
    post :create_new_password, {:user=>{:password=>"123456", :password_confirmation=>"123456"}, :reset_password_key=>user.reset_password_key} 
end 
 

在我看来,我有以下形式:

 

=simple_form_for @user, :url=>create_new_password_path do |f| 
    =f.input :password, :label=>I18n.t("activerecord.attributes.user.email") 
    =f.input :password_confirmation, :label=>I18n.t("activerecord.attributes.user.password_confirmation") 
    =f.submit I18n.t "activerecord.actions.user.create_new_password" 

 

当我提交表单,我得到:

 

No route matches "/user/create_new_password/OqQxYTgjYKxXgvbAsTsWtMnIpMOpsjCRzLGZmJZLSbYtjvcvdpO" 
 

大字符串是reset_password_key。

我已经在功能测试中用reset_password_key的相同值对它进行了测试。

进行耙路线相关的输出是:

 

create_new_password POST|GET /user/create_new_password/:reset_password_key(.:format) {:controller=>"users", :action=>"create_new_password"} 
 

我失去了一些东西......

+0

不得不问:你开始,因为编辑路由服务器?如果是这样,你可以发布你的`config/routes.rb`文件的内容吗?谢谢,祝你好运! – 2011-02-10 00:06:04

回答

1

至于回答到BinaryMuse的评论,我发现了什么问题?我查了请求在萤火虫,并发现_method = put与POST一起发送。 Rails的聪明性检测到我正在编辑用户(@user)的现有实例,因此它使用参数_method将POTS默认为PUT。

问题是,在我的路线中,我没有在通过数组中的方法PUT。刚改为:

 

match "user/create_new_password/:reset_password_key" =>"users#create_new_password",:via=>[:get, :put], :as=>:create_new_password 
 

和Controller:

 

def create_new_password 
    if request.put? 
     #change password 
    else 
    #render template 
    end 

end