Ruby on Rails: prevent new page execute through default application -


i'm beginning learn ruby on rails , know every time create new page in app/assets/views pages rendered out through layouts/application has html markup , <%= yield %>

but if want create home page different page yield (or different layout aside default application page), how do won't have go through default application?

thanks!

there few ways achieve this.

controller wide

in controller, can use layout method

class mycontroller < applicationcontroller   layout :name_of_my_layout end 

this use app/views/layout/name_of_my_layout.html.erb layout actions under mycontroller

you can pass method layout returns name of layout

class mycontroller < applicationcontroller   layout :random_layout    private    def random_layout     %[layout1 layout2 layout3].sample   end end 

the method random_layout determines layout used action under mycontroller per request.

per render

you can override above option passing layout option render calls.

class mycontroller < applicationcontroller   layout :name_of_my_layout    def index     ...     render layout: false # no layout   end    def new     ...     render layout: 'my_super_duper_layout_for_the_new_action'   end end 

naming convention

you can use name of controller name of layout. example have posts controller, if have app/views/layouts/posts.html.erb, rails use instead of app/views/layouts/application.html.erb if have not specified layout in controller.


Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -