How can i make a view i开发者_高级运维ndex working with 2 actions show and index in the same view ??? I`m new in ruby on rails.
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
精彩评论