2011-09-15 36 views
1

我已经安装在我的Rails应用一些简单的关联:Rails的重定向问题

resources :properties do 
resources :units 
end 

更新单元后:

的 'localhost:3000 /属性/ 2 /单位/ 3 /编辑'

我想将其重定向回适当的位置。

我点击 “更新” 我重定向回后:

'本地主机:3000 /辆/ 3',而是应该去的 'localhost:3000 /属性/ 2 /单位/ 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的功能,适当的使用?我仍然试图熟悉路线如何运作,但我觉得这应该起作用?

谢谢!

回答

0

你快到了。您应该重定向到:

format.html { redirect_to(property_unit_path(@property, @unit), :notice => 'Unit was successfully updated.') } 

请注意,您必须使用单一版本的路由帮助器方法才能工作。有关更多详情,请查看routing上的导轨指南。