我不太了解 MVC 的流程。页面请求转到路由,该路由调用 Controller 中的操作。但是为什么在那之后会调用一个 View 呢?我不太明白是哪个代码调用了 View 并将其显示给用户。
root 'controllername#index'
def index
end
最佳答案
Controller Action 将搜索具有相同名称的 View ,例如 Controller 操作 index
将在其关联目录中搜索诸如 index.html.erb
和 index.html.haml
之类的 View 。要在没有 View 的情况下执行 Controller 操作,可以使用类似 render :nothing => true
的东西。
更多信息可以在 Action View guide 中找到.
关于ruby-on-rails - 为什么在调用 Controller 后调用 html.erb 文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44877465/