在同一视图中使用 2 个操作,索引和显示?
我怎样才能使视图索引与同一个视图中的 2 个操作显示和索引一起使用???我是 ruby on Rails 的新手。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
目前尚不清楚为什么您希望
show
方法与index
相同,但最简单的方法是重定向:另一种方法是呈现相同的模板:
如果您使用
render
方法,则必须填充与index
方法中相同的实例变量,否则您的视图可能无法运行。如果您想确保设置相同的变量,您也可以这样做:It's not quite clear why you'd want a
show
method to be the same as anindex
but the easiest approach is to redirect:The alternative is to render the same template:
If you're using the
render
method you will have to populate the same instance variables as in theindex
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: