Rails项目:Project
有很多Ticket
's。RoR:更新操作。渲染路径时出现错误
路径编辑票:/projects/12/tickets/11/edit
当更新票和验证失败,我用render :action => "edit"
。
然而,当编辑视图渲染这段时间,路径改变为/tickets/11/
这意味着我失去了一些参数。我怎样才能保持原来的道路?
的routes.rb:
resources :projects do
resources :tickets
end
resources :tickets
tickets_controller.rb
def new
@ticket = Ticket.new
end
def create
@ticket = Ticket.new(params[:ticket])
@ticket.user_id = session[:user_id]
respond_to do |format|
if @ticket.save
format.html { redirect_to project_path(@ticket.project), :notice => "Ticket was created." }
else
format.html { render :action => "new" }
end
end
end
def edit
@ticket = Ticket.find(params[:id])
end
def update
@ticket = Ticket.find(params[:id])
respond_to do |format|
if @ticket.update_attributes(params[:ticket])
format.html { redirect_to project_ticket_path(@ticket.project, @ticket), :notice => "Ticket was updated." }
else
format.html { render :action => "edit" }
end
end
end
我们可以看看你的'routes.rb'吗? – gabrielhilal 2013-02-11 12:27:16
更新了问题。 – user1121487 2013-02-11 12:29:45