开发者

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

开发者 https://www.devze.com 2023-04-12 15:26 出处:网络
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

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
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号