Rails 项目:Project
有很多Ticket
。
编辑工单的路径:/projects/12/tickets/11/edit
当更新票证并且验证失败时,我使用render :action => "edit"
.
但是,当这次编辑视图渲染时,路径变为/tickets/11/
这意味着我丢失了一些参数。我怎样才能保持原来的路径?
路线.rb:
resources :projects do
resources :tickets
end
resources :tickets
门票控制器.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