https://guides.rubyonrails.org/layouts_and_rendering.html

controller进行渲染编辑页面

render :edit
render action: :edit
render "edit"
render action: "edit"
render "books/edit"
render template: "books/edit"

渲染其他内容:

render plain: "OK"
render html: helpers.tag.strong('Not Found')
render json: @product

 

render xml: @product

 

render js: "alert('Hello Rails');" render body: "raw"

或者直接报错:

render file: "#{Rails.root}/public/404.html", layout: false
controller进行设置渲染模板
class ProductsController < ApplicationController
 
  def show
    @product = Product.find(params[:id])
  end
  private
    def products_layout
      @current_user.special? ? "special" : "products"
    end
end

application_controller确认进行渲染的公共样式

class ApplicationController < ActionController::Base
  layout "main"
end

不渲染:

class OldArticlesController < SpecialArticlesController
  layout false
  def show
    @article = Article.find(params[:id])
  end
  def index
    @old_articles = Article.older
    render layout: "old"
  end
  # ...
end

3 Structuring Layouts

使用yield,等,asset_pipeline