Search code examples
ruby-on-railstemplatesrenderpartial

Rails: render partial with selected controller and action in view


I have a Rails app where on the home page home/index.html.erb, I show a partial for the model workorders. It currently defaults to the home_controleer.rb with the action index.

Can I select the workorders_controller.rb and action index2?

I tried this in the home/index.html.erb view file:

<%= render :partial => "workorders/index7", :controller => "workorders", :action => "index2" %>

But it's not working.


Solution

  • Try this instead:

    <%= render :template => "workorders/index2" %>

    source: https://stackoverflow.com/a/6051812/2128691

    edit: in response to your last comment...

    I haven't really worked with bootstrap, but maybe you could do something like this [pseudocode]:

    def home
      if [x condition] 
        redirect_to index_seven_path
      else
        render :action => [y action]
      end
    end