3

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.

Reddirt
  • 5,913
  • 9
  • 48
  • 126

1 Answers1

3

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
Community
  • 1
  • 1
dax
  • 10,779
  • 8
  • 51
  • 86
  • I changed it. But, it's running the action `index` in the controller `home` instead of action `index7` in controller `workorders` – Reddirt Aug 19 '13 at 19:16
  • that's strange - is it reaching this request? maybe it's getting redirected to home#index before it hits this? – dax Aug 19 '13 at 19:21
  • It's displaying the `workorders/index7.html.erb` view. I changed it from `_index7.html.erb` (a partial). But, it's not executing the index7 action in `workorders_controller.rb`. Instead it's executing the `index` action in the `home_controller.rb`. – Reddirt Aug 19 '13 at 20:15
  • If I use this url `http://localhost:5000/workorders/index7` then it executes the `index7` action in the `workorders` controller. But, I want it to show on the home page not on a separate page. – Reddirt Aug 19 '13 at 20:17
  • could you make `http://localhost:5000/workorders/index7` a named route and call it (say `redirect_to index_seven_path`) where you need it? Is the index7 action **always** what will be called, or it's conditional on something? – dax Aug 19 '13 at 20:36
  • I'm using Bootstrap and I'm rendering page `index7` in a tab and another page `index8` in a 2nd tab. – Reddirt Aug 19 '13 at 20:55