Rails: Pass parameters with render :action?

前端 未结 4 1588
时光取名叫无心
时光取名叫无心 2020-12-08 07:14

I have a form that displays differently depending on the parameter it was called with.

Ex.

testsite.local/users/new?type=client

So

4条回答
  •  温柔的废话
    2020-12-08 07:51

    Extract for Rails Guides

    Using render with :action is a frequent source of confusion for Rails newcomers. The specified action is used to determine which view to render, but Rails does not run any of the code for that action in the controller

    I believe your new?type=client is used to setup some kind of variable in your new action? And the variable is later used in your new.html.erb view?

    Then you need to change a little bit your create action like this:

      else
         # add code here to setup any variable for type = client
         # and which will be used in your view
         render :action => 'new'
      end
     end
    

提交回复
热议问题