Hello, everyone I am a student studying Ruby Onrails.
I have a question in the Layout section of the Ruby On-Rails web page.
When you create a rails project, the View/layout/application.html.erb layout is applied by default.
I want to make View/layout/loginlayout.html.erb and apply a different layout for each page What should I do?
ruby
No, it's not I want to give a different layout for each view.
render layout: "special_layout"
After creating another layout, I think it's possible to do it like this on the controller
I'll have to see if it works or not.
Here's the document
http://guides.rubyonrails.org/layouts_and_rendering.html
You can also specify the use of layout on the controller as shown below. Below you will specify the layout name directly.
class WatcherController < ApplicationController
layout "login_layout"
end
If you turn over the symbol with a factor, call the method as shown below. This means that you can also do layout branching depending on the conditions.
class WeblogController < ActionController::Base
layout :writers_and_readers
def index
# # fetching posts
end
private
def writers_and_readers
logged_in? ? "writer_layout" : "reader_layout"
end
end
A per-view layout branch can be called in an action method like render:layout=> 'login_layout'
.
Please refer to the API document for more information on setting the controller/view layout.
http://api.rubyonrails.org/classes/ActionView/Layouts.html
© 2024 OneMinuteCode. All rights reserved.