2013-12-20 25 views
1

我控制器的方法中的某部分:通行证到URL变量与轨渲染动作

*** 
else 
    @ord_question = @vq 
    render :action => :new, :layout => 'admin', :locals => {:order_question_id => @order_question_id} 
end 

所有的代码是在这里:

http://pastebin.com/nNMF1hag

在我的新方法,之前我忘记输入一些字段并提交它(validator presence_of),我的网址是这样的:

...order_answers/new?order_question_id=15 

但是我需要在url order_question_id = 15中保存这个get变量,即使在我使用render:action进入我的else方法之后。

我该如何添加渲染:action url param?

+0

我想你应该重新考虑你传递'order_question_id'到表单操作的方式。我猜这里可以使用嵌套资源。 http://guides.rubyonrails.org/routing.html#nested-resources –

+0

@MarekLipka它很长,重建,让我们来做这个问题... – brabertaser19

回答

0

对于在轨使用

redirect_to path 

标准建立在轨道4,5

def create 
    @country = Country.new(country_params) 
    respond_to do |format| 
    if @country.save 
     format.html { redirect_to @country, notice: 'Country was successfully created.' } 
     format.json { render action: 'show', status: :created, location: @country } 
    else 
     format.html { render action: 'new' } 
     format.json { render json: @country.errors, status: :unprocessable_entity } 
    end 
    end 
end 
+0

但我不会有错误消息的形式? – brabertaser19

+0

redirect_to只有在动作成功时才​​会完成。否则rails会使用@vars并自行将文件存档。 – devanand

+0

主要的麻烦是,我需要它时,它不保存... – brabertaser19