【发布时间】:2015-11-23 20:12:29
【问题描述】:
我刚开始学习 Rails。我对以下部分有疑问。
控制器:
book_controller.rb
class BookController < ApplicationController
end
查看:
list.html.erb
<% if @books.blank? %>
<p>There are not any books currently in the system.</p>
<% else %>
<p>These are the current books in our system</p>
<ul id="books">
<% @books.each do |c| %>
<li><%= link_to c.title, {:action => 'show', :id => c.id} -%></li>
<% end %>
</ul>
<% end %>
路由器:
get 'list' => 'book#list'
当我转到localhost:3000/list 时,它会显示list.html.erb 的内容。当我在 Controller 中没有 list 操作时,会发生什么情况?我怎么理解错了?
【问题讨论】:
-
Rails 自动处理...您的路线知道哪个控制器要执行哪个操作.. 以及必须从那里显示哪个默认视图.. 如果所有约定都在那里,事情将在没有任何如您所见,打扰了。
标签: ruby-on-rails model-view-controller