Ruby%20On%20Rails%20Interview%20Questions%20and%20Answers
Question: What is the purpose of Layouts in Ruby on Rails?Answer:Layouts are partial ruby/html files that are used to render the content pages. There are placed in the folder: app/views/layouts Items that you would typically put in this folder are things like headers/footers, navigation elements, etc. Here’s a sample layout file: /app/views/layout/application.html.erb <html lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>Learning System | <%= @page_title || 'Admin Area' %></title> <meta name="author" content="Anil Punjabi"> <%= stylesheet_link_tag('public', 'admin', :media => 'all') %> <%= javascript_include_tag('application') %> </head> <body> <div id="header"> <h1>Learning System</h1> </div> <div id="main"> <% if !flash[:notice].blank? %> <div class="notice"> <%= flash[:notice] %> </div> <% end %> <div id="content"> <%= yield %> </div> </div> <div id="footer"> <p id="copyright">© / Anil Punjabi</p> </div> </body> </html> Say you are trying to access the page as shown below: Then the contents of the index.html.erb would be placed above in the section shown under <% yield %> above and sent back to the user. |
Is it helpful?
Yes
No
Most helpful rated by users:
- What is Ruby On Rails?
- Why Ruby on Rails?
- Explain how (almost) everything is an object in Ruby.
- What are Gems and which are some of your favorites?
- How would you declare and use a constructor in Ruby?