user977653
user977653

Reputation: 13

Using 2 actions in the same view, index and show ?

How can i make a view index working with 2 actions show and index in the same view ??? I`m new in ruby on rails.

Upvotes: 1

Views: 696

Answers (1)

tadman
tadman

Reputation: 211740

It's not quite clear why you'd want a show method to be the same as an index but the easiest approach is to redirect:

def show
  redirect_to(:action => :index)
end

The alternative is to render the same template:

def show
  render(:action => 'index')
end

If you're using the render method you will have to populate the same instance variables as in the index method or your view may not be able to run. If you want to be sure that the same variables are set, you can also do this:

def show
  self.index
  render(:action => 'index')
end

Upvotes: 1

Related Questions