Why do I need `render layout: false` in my Rails controller action?

前端 未结 2 1467
星月不相逢
星月不相逢 2021-01-19 17:21

I\'m use the remote: true idiom from the Working with Javascript in Rails guide:

# new.html.slim
= form_for @thing, remote: true do |f|
  f.text         


        
2条回答
  •  太阳男子
    2021-01-19 17:39

    With most of the options to render, the rendered content is displayed as part of the current layout.

    You can use the :layout option to tell Rails to use a specific file as the layout for the current action:

     render layout: false
    

    You’ve heard that Rails promotes “convention over configuration.” Default rendering is an excellent example of this. By default, controllers in Rails automatically render views with names that correspond to actions

    You can use it to avoid the render false for the particular action which may affect you in code latency

     layout false
     layout 'foo', :except => :create
    

提交回复
热议问题