render :action with params

丶灬走出姿态 提交于 2019-12-21 06:58:43

问题


I have one Class with 2 methods. The first method is called by the view with some GET parameters ( params[:page] ). I would like to save those params and send them by a render action to my second method.

class exemple
  def first
    ## sql save of params[:page] 
    render :action => "second"
  end

  def second
    ##
    ## Here I need my params[:page] to do paginate stuff
    ##
    respond_to do |format|
      format.html
    end
  end
end

So my question is : How can I send params with a render :action ?

thanks :)


回答1:


render :action => "second"

When you render, then your method written in :action is not called, only the view with that action name is called.

In your example, when you render, then your method second is not called but you are instead rendering the second.html.erb view.

For more details refer to this.

To call that method you have to use redirect_to, which looks something like the following:

redirect_to :action => "second", :page=> 4


来源:https://stackoverflow.com/questions/3150641/render-action-with-params

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!