Rails Nested Singular Resource Routing

大兔子大兔子 提交于 2019-12-03 22:59:39

After looking around, it appears that the form generating the update had an incorrect url. If anyone is seeing this issue, it's because I had my form set up as:

form_for [@user, @profile] do |f| ...

This caused the form action to have the incorrect url (of the offending form above). Instead, I used

form_for @profile, :url => user_profile_path(@user) do |f| ...

and everything seemed to work.

You should redirect to user_profile_path(@user) since as your routes says it is:

/users/:user_id/profile(.:format)

If you look at it closely, then you will see, that there is only :user_id parameter needed, thou it is only @user in a path.

/users/:user_id/profile/:id(.:format)

It would be correct if you had resource*s* :profiles in your routes.rb, then as well you could use your path as in your example.

user_profile_path(@user) should be correct. You're sure that one is returning mydomain.com/users/4/profile.22?

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!