我是 Rails 新手,我不确定如何链接到我刚刚创建的不同视图。我现在在索引视图上,我想链接到同一文件夹内的 eat.html.erb 视图。我是否必须向控制器添加代码才能进行设置?我认为向控制器添加代码只是为了链接到视图听起来像是一些不必要的工作。
2 回答
Short answer, you create a link with the link_to method of the url helper: http://api.rubyonrails.org/classes/ActionView/Helpers/UrlHelper.html
Here's an example:
<%= link_to "eat", eat_path %>
However, your question indicates that you don't quite have a grasp of the rails basics*. Sergio has suggested you get a book, but a good/free place to start learning is here: http://guides.rubyonrails.org/getting_started.html
You should go through that from start to end and you will get a pretty good understanding of the basic concepts in rails.
*You're asking to link to a partial (which starts with an underscore), which isn't actually a page.
对于您想要完成的任务,您需要在控制器中使用“defeat”创建一个显示动作。您在视图上的代码应该是...
<%= link_to "TITLE OF PAGE HERE", FOLDERNAME_eat_path %>
我建议您使用“a href”来完成您想要完成的任务。