IT・技術研修ならCTC教育サービス

サイト内検索 企業情報 サイトマップ

研修コース検索

Rails技術者認定ブロンズ試験 模擬問題(11~20) - Rubyの研修・教育ならCTC教育サービス

Rails技術者認定ブロンズ試験 模擬問題

問題は四択で10問ずつ合計70問あります。各問題には解答がついていますが、はじめは閉じた状態でトライしてみてください。
10問毎に「終了/採点」ボタンをクリックすると採点ができます。次の10問へお進みください。繰り返しトライすることも可能です。

模擬問題 11~20 (1~10 / 21~30 / 31~40 / 41~50 / 51~60 / 61~70

問11.'/'にアクセスされたときに、'welcome#index'アクションが呼び出されるように定義するために、(1)に入れるコードとして適切なものを一つ選びなさい。

   1: Rails3::Application.routes.draw do
   2:   __(1)__
   3: end
1. root :to => 'welcome#index'
2. root 'welcome#index'
3. match :root => 'welcome#index'
4. get :root => 'welcome#index'
問11の解答

解答:1

問12. '/users/1/preview'にアクセスされたときに、'users#preview'アクションが呼び出されるように定義するために、(1)に入れるコードとして適切なものを一つ選びなさい。

   1: Rails3::Application.routes.draw do
   2:   resources :users do
   3:     __(1)__ do
   4:       get :preview
   5:     end
   6:   end
   7: end
1. collection
2. namespace
3. member
4. match
問12の解答

解答:3

問13.current_user.admin? の実行結果がfalseになるときに、すべてのアクションが実行されないようにしたい場合に、(1)に入れるコードとして適切なものを一つ選びなさい。

   1: class Admin::UsersController < ApplicationController
   2:   __(1)__
   3:
   4:   def index
   5:     @users = Users.all
   6:   end
   7:
   8:   private
   9:   def require_admin
  10:     redirect_to welcome_path unless current_user.admin?
  11:   end
  12: end
1. before :require_admin
2. before_filter :require_admin
3. after_filter :require_admin
4. after :require_admin
問13の解答

解答:2

問14.flashに「Book was successfully created.」というメッセージを設定し、リダイレクトをするときに、(1)に入れるコードとして適切なものを一つ選びなさい。

   1: class BooksController < ApplicationController
   2:   def create
   3:     @book = Book.new(params[:book])
   4:     if @book.save
   5:       __(1)__
   6:     else
   7:       render :action => :new
   8:     end
   9:   end
  10: end
1. redirect_to @book, :message => "Book was successfully created."
2. redirect_to @book, :notice => "Book was successfully created."
3. redirect @book, :notice => "Book was successfully created."
4. redirect @book, :message => "Book was successfully created."
問14の解答

解答:2

問15.リスト1のモデルが定義されているときに、リスト2のコードでユーザー名がユーザーページへのリンクになるように、(1)に入れるコードとして適切なものを一つ選びなさい。

   リスト1
   1: class User < ActiveRecord::Base
   2: end

リスト2 1: <% User.all.each do |user| %> 2: <%= __(1)__ user.name, user %> 3: <% end %>
1. link_for
2. link_tag
3. link_to
4. link
問15の解答

解答:3

問16.リスト1のlayoutテンプレートから、リスト2のアクションのテンプレートを読み込んだときに、ブラウザのタイトルが"Hello world"になるように、(1)に入れるコードとして適切なものを一つ選びなさい。

   リスト1
   1: <html>
   2:   <head>
   3:     __(1)__
   4:   </head>
   5:   <body>
   6:     <%= yield %>
   7:   </body>
   8: </html>

リスト2 1: <% content_for :head do %> 2: <title>Hello world</title> 3: <% end %>
1. <%= yield :head %>
2. <%= yield :partial => 'head' %>
3. <%= render :head %>
4. <%= render :partial => 'head' %>
問16の解答

解答:1

問17.リスト1のconfig/routes.rbに以下の定義されているときに、リスト2のコードで生成される文字列として適切なものを一つ選びなさい。

   リスト1
   1: Rails3::Application.routes.draw do
   2:   resources :users
   3: end

リスト2 1: <%= url_for User.find(1) %>
1. /users/1/edit
2. /users/new
3. /users
4. /users/1
問17の解答

解答:4

問18.デフォルトの送信元を設定するコードとして適切なものを一つ選びなさい。

   1: class NotifierMailer < ActionMailer::Base
   2:   __(1)__
   3:
   4:   def welcome(recipient)
   5:     mail :to => recipient.email
   6:   end
   7: end
1. default :from => 'no-reply@example.com'
2. default :from, 'no-reply@example.com'
3. from 'no-reply@example.com'
4. send_from 'no-reply@example.com'
問18の解答

解答:1

問19.フィクスチャを読み込むときに、(1)に入れるコードとして適切なものを一つ選びなさい。

  1: class EmployeesControllerTest < ActionController::TestCase
  2:   __(1)__
  3:   test "the truth" do
  4:     assert true
  5:   end
  6: end
1. fixture :companies
2. fixtures :companies
3. load :companies
4. load_fixtures :companies
問19の解答

解答:2

問20.レスポンスが成功(200)であることをテストするときに、(1)に入れるコードとして適切なものを一つ選びなさい。

  1: class UsersControllerTest < ActionController::TestCase
  2:   test "should get index" do
  3:     get :index
  4:     __(1)__
  5:   end
  6: end
1. assert_response :successful
2. assert_response :success
3. assert :response => :success
4. assert :response => :successful
問20の解答

解答:2

※解答完了後は「終了/採点」をクリックし、結果が表示されるのをお待ちください。

※解答をクリアしてもう一度トライされる場合は「解答をクリア」をクリックしてください。

模擬問題 11~20 (1~10 / 21~30 / 31~40 / 41~50 / 51~60 / 61~70