热门面试题与答案和在线测试
面向面试准备、在线测试、教程与实战练习的学习平台

通过聚焦学习路径、模拟测试和面试实战内容持续提升技能。

WithoutBook 将分主题面试题、在线练习测试、教程和对比指南整合到一个响应式学习空间中。

面试准备

Ruby On Rails 面试题与答案

问题 31. What is the purpose of Layouts in Ruby on Rails?

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:
http://mysite.com/page/index
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.

这有帮助吗? 添加评论 查看评论
 

问题 32. IS IT POSSIBLE TO EMBED PARTIAL VIEWS INSIDE LAYOUTS? HOW?

That is the purpose of layouts. You embed partial views inside the file /app/views/layout/application.html.erb and then whenever you render any page this layout is merged with it.

这有帮助吗? 添加评论 查看评论
 

问题 33. What is Rake in Ruby on Rails?

Rake is a popular ruby gem that makes the job of running tasks simpler. 

Rake is most often used for DB tasks, but it can be used for m

The common DB commands are:

rake db:migrate
rake db:reset

You can use cron to schedule rake tasks. 

Sometimes you would create a dataloader.rake file and put it in the lib/tasks folder so that it can be used to populate the database on startup.

这有帮助吗? 添加评论 查看评论
 

问题 34. What is Capistrano?

Capistrano is a popular deployment tool — it allows developers to push code from their desktop to the servers. 

这有帮助吗? 添加评论 查看评论
 

问题 35. What is Eager Loading in Ruby on Rails?

Eager loading is a great optimization strategy to reduce the number of queries that are made against the DB.

Say you are finding 10 employees and then you are looking for their post codes. Then your query would appear something like this:

clients = Client.limit(10)
clients.each do |client|
  puts client.address.postcode
end

This may seem fine at first look but really this implementation leaves much to be desired. It makes 11 DB calls just to get the results.

Now you can optimize this query by making a slight change in the request like this:

clients = Client.includes(:address).limit(10)
clients.each do |client|
  puts client.address.postcode
end 

This new request makes two SQL calls like this:

SELECT * FROM clients LIMIT 10
SELECT addresses.* FROM addresses
    WHERE (addresses.client_id IN (1,2,3,4,5,6,7,8,9,10))
So, as you can see it really loads a lot more upfront and therefore it is called eager loading.

这有帮助吗? 添加评论 查看评论
 

用户评价最有帮助的内容:

版权所有 © 2026,WithoutBook。