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.

1 Answer 1

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
Sign up to request clarification or add additional context in comments.

6 Comments

I changed it. But, it's running the action index in the controller home instead of action index7 in controller workorders
that's strange - is it reaching this request? maybe it's getting redirected to home#index before it hits this?
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.
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.
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?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.