路由是使用ID有action并且action在提交表单后有ID
有一个模型用户 has_one user_profile 和 User_Profile属于用户
我在用户控制器中
def personal
@user = User.find_by_id(params[:id])
@user_profile = @user.user_profile
@user_profile ||= @user.build_user_profile
end
def update_personal
@user = User.find_by_id(params[:id])
if @user.user_profile.update_attributes(params[:user_profile])
flash[:notice] = "OK"
redirect_to @user
else
flash[:notice] = "Fail"
render :action => 'update_personal'
end
end
我有:在我的personal.html.erb视图中我有:
<% semantic_form_for @user_profile, :url => { :action => "update_personal"} do |form| %>
<%= form.inputs %>
<%= form.buttons %>
<%end%>
在轮盘上我有:
map.resources :users, :member => {
:personal => :get,
:update_personal => :put
}
现在奇怪的是我可以做:
users/1/personal
看看但当我提交时,我收到此错误:
Unknown action
No action responded to 1.
它正在尝试查找名为 1 的操作。
任何人都可以指出我正确的方向吗?
I have a model User that has_one user_profile and a User_Profile belongs_to user
in the User controller I have:
def personal
@user = User.find_by_id(params[:id])
@user_profile = @user.user_profile
@user_profile ||= @user.build_user_profile
end
def update_personal
@user = User.find_by_id(params[:id])
if @user.user_profile.update_attributes(params[:user_profile])
flash[:notice] = "OK"
redirect_to @user
else
flash[:notice] = "Fail"
render :action => 'update_personal'
end
end
In my personal.html.erb view I have:
<% semantic_form_for @user_profile, :url => { :action => "update_personal"} do |form| %>
<%= form.inputs %>
<%= form.buttons %>
<%end%>
And on the rountes I have:
map.resources :users, :member => {
:personal => :get,
:update_personal => :put
}
Now the strange thing is that I can do:
users/1/personal
to see the form but when I submit I get this error:
Unknown action
No action responded to 1.
It's trying to find an action with the name 1.
Can anyone point me out on the right direction?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
刚刚又遇到了这个问题,终于明白了问题所在,找到了解决办法。
这次我使用 getJason 进行 ajax 调用。
因为调用是一个 get,并且在我的路线中我有一个 update_xxxxxx => :放,
路由被忽略并使用默认的 :controller/:action/:id 。
我只需要把 update_xxxx =>; :get ,问题就解决了。
也许这会对某人有所帮助。
I just got the problem again, and finally understood the problem and found the solution.
This time i was using an ajax call using getJason.
Because the call was a get, and in my routes I had a update_xxxxxx => :put,
the route was ignored and the default :controller/:action/:id was used.
I just had to put the update_xxxx => :get and the problem was solved.
Maybe this will help someone.