Rails 离开呈现 application.html.erb 而不是想要的视图

Rails aways renders the application.html.erb instead of wanted views

我在 Rails 上的 Ruby 应用程序总是呈现 layouts/application.html.erb 视图,而不是我想要的视图。有谁知道为什么会这样? 我的路线文件如下所示:

   Rails.application.routes.draw do
     root 'startup#index'
     resources :users
   end

而我的 application_cotroller.rb 几乎是空的:

   class ApplicationController < ActionController::Base
      protect_from_forgery with: :exception
   end

默认情况下,Rails 中的控制器操作会呈现您的操作的视图模板,并封装到布局中(即 application/layout

ActionView::TemplateHandlers 管理扩展的查找(.html.erb、.html.haml、.json.erb 等...)

因此,在名为索引的操作中,除非您自己调用 render,否则您将获得此隐式调用:

def edit
  # your code
  render action :'edit', layout: 'application/layout' # implicitly called
end

Rails 然后将开始处理您的布局,并将您的编辑模板的内容放在布局中的任何 yield 位置。因此,典型的布局将如下所示:

<!doctype html>
<head>
</head>
<body>
  <!-- layout content before view -->

  <%= yield %>

  <!-- layout content after view -->
</body>