一些嵌套资源路由遇到问题。我想要做的是链接到用户的个人资料页面以进行编辑。在我看来,它写成:
<%= link_to "Edit Profile", edit_user_profile_path(current_user) %>
哪些错误:
No route matches {:action=>"edit", :controller=>"profiles", :user_id=>#<User id: 1, email: "EDITEDOUT", hashed_password: "EDITEDOUT", created_at: "2011-01-20 18:30:44", updated_at: "2011-01-20 18:30:44">}
在我的 routes.rb 文件中,它看起来像这样:
resources :users do
resources :profiles, :controller => "profiles"
end
我检查了我的 Rake 路线,它给了我一个有效的选项:
edit_user_profile GET /users/:user_id/profiles/:id/edit(.:format) {:action=>"edit", :controller=>"profiles"}
我可以手动导航到。为了采取好的措施,这是我的控制器的证明:
class ProfilesController < ApplicationController
def edit
@user = current_user
@profile = current_user.profile
end
def update
@user = current_user
@profile = current_user.profile
respond_to do |format|
if @profile.update_attributes(params[:profile])
format.html { redirect_to(orders_path, :notice => "Your profile has been updated.") }
format.xml { head :ok }
else
format.html { render :action => "edit" }
format.xml { render :xml => @profile.errors, :status => :unprocessable_entity }
end
end
end
end
无论如何,我一直在追踪这个问题。任何指针都会有所帮助。对于我的数据库设计,配置文件属于一对一关系的用户。我希望这只是一些新事物,我没有注意到一组新的眼睛可能会有所帮助。