bypass application.html.erb in Rails app

后端 未结 3 965
心在旅途
心在旅途 2021-02-02 10:15

I have an application.html.erb file which sets out layout for every pages in my app (header, footer etc.) like a typical Rails app.

However, I would like to have a landi

相关标签:
3条回答
  • 2021-02-02 10:39

    You can set a layout in your render function:

    render {other arguments}, :layout => :homepage
    

    You can also set that option to false to not use any layout at all.

    You can do something similar if you want an entire controller to use a custom layout:

    class MyController < ApplicationController
    
        layout :homepage
    
        #...
    end
    

    Hope that helps!

    0 讨论(0)
  • 2021-02-02 10:41

    In the controller that renders the view, change the render to:

    render :layout => false
    

    You can read more about options to render and how to work with layouts at the Rails guide to render and layouts.

    0 讨论(0)
  • 2021-02-02 10:48

    Use

    render :layout => false
    

    or

    render :layout => 'whatever'
    

    in your action. If you are using a separate LandingController you simply can create a app/views/layouts/landing.html.erb which will be picked up or you can override the layout via

    class LandingController < ApplicationController
      layout 'whatever'
      ...
    end
    
    0 讨论(0)
提交回复
热议问题