ruby-on-rails - 为什么在调用 Controller 后调用 html.erb 文件?

标签 ruby-on-rails ruby

我不太了解 MVC 的流程。页面请求转到路由,该路由调用 Controller 中的操作。但是为什么在那之后会调用一个 View 呢?我不太明白是哪个代码调用了 View 并将其显示给用户。

root 'controllername#index'

def index
end

最佳答案

Controller Action 将搜索具有相同名称的 View ,例如 Controller 操作 index 将在其关联目录中搜索诸如 index.html.erbindex.html.haml 之类的 View 。要在没有 View 的情况下执行 Controller 操作,可以使用类似 render :nothing => true 的东西。

更多信息可以在 Action View guide 中找到.

关于ruby-on-rails - 为什么在调用 Controller 后调用 html.erb 文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44877465/

相关文章:

ruby-on-rails - 如何 sanitizer 葡萄参数

ruby-on-rails - 关于在 Ruby on Rails 中实现代理键的问题

ruby-on-rails - 使用 ruby​​ 从表中获取常用值

ruby-on-rails - 使用 Apache ReverseProxy 复制 TorqueBox 上 Rails 应用程序路径中的上下文

ruby - 错误 : "fatal: I don' t handle protocol `` git` when using bundle install

ruby - 如何在Ruby中出错时做些什么?

ruby-on-rails - 如何使用 Ruby 推送 Celery 任务

ruby-on-rails - Rails 播种 boolean 值不起作用

ruby-on-rails - Omniauth-facebook 并不总是注销用户

ruby - 使用字典条目枚举 ruby​​ 字典键