Rails 重定向问题
我在 Rails 应用程序中设置了一些简单的关联:
resources :properties do
resources :units
end
更新单元后:
'localhost:3000/properties/2/units/3/edit'
我想重定向回适当的位置。
单击“更新”后,我被重定向回:
'localhost:3000/units/3',但应该转到'localhost:3000/properties/2/units/3/'
在我的单位控制器中,我有:
if @unit.update_attributes(params[:unit])
format.html { redirect_to(property_units_path(@property, @unit), :notice => 'Unit was successfully updated.') }
format.xml { head :ok }
else
format.html { render :action => "edit" }
format.xml { render :xml => @unit.errors, :status => :unprocessable_entity }
end
是这样的在我的redirect_to函数中适当使用吗?我仍在尝试熟悉路线的运作方式,但我觉得这应该可行吗?
谢谢!
I have setup some simple associations in my rails app:
resources :properties do
resources :units
end
After updating a unit:
'localhost:3000/properties/2/units/3/edit'
I want to be redirected back to the appropriate location.
after I click "Update" I am redirected back to:
'localhost:3000/units/3', but should go to 'localhost:3000/properties/2/units/3/'
In my units controller, I have:
if @unit.update_attributes(params[:unit])
format.html { redirect_to(property_units_path(@property, @unit), :notice => 'Unit was successfully updated.') }
format.xml { head :ok }
else
format.html { render :action => "edit" }
format.xml { render :xml => @unit.errors, :status => :unprocessable_entity }
end
Is this the appropriate use in my redirect_to function? I am still trying to become familiar with how the routes work but I feel like this should work?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你快到了。您应该重定向到:
请注意,您必须使用路由帮助器方法的单数版本才能使其工作。有关更多详细信息,请查看有关 路由 的 Rails 指南。
You are almost there. You should redirect to:
Note that your must use the singular version of the routing helper method for this to work. For more details check the rails guide on routing.