Ruby Flashcards
Kết quả khi chạy câu lá»nh sau là gì? x,y,z = [1,2,3]
2. x = 1; y = 2; z = 3
Mảng a sẽ gá»m những phần tá» nà o sau khi chạy các câu lá»nh sau? a = [0, 1, 4, 9, 16] a << [25]
4. [0, 1, 4, 9, 16, [25]]
Trong các khẳng Äá»nh sau, khẳng Äá»nh nà o là Äúng?
1. Lambda có kiá»m tra sá» lượng Äá»i sá» còn Proc thì không
Những gì ÄÆ°á»£c tạo ra khi chạy câu lá»nh sau?rails generate controller StaticPages home help
2. controller, views, helper, assets, route
Theo RESTful, những routes nà o sẽ ÄÆ°á»£c cung cấp cho resource user? Rails.application.routes.draw do resources :usersend
3. index, show, new, create, edit, update, destroy
Äâu là ba phần má» rá»ng tên file (Äuôi) thông thưá»ng nhất mà Preprocessor engines sá» dụng?
4. .scss, .coffee, .erb
Là m thế nà o Äá» xá» lý lá»i bảo máºt khi sá» dụng tÃnh nÄng Mass Assignment trong Rails 4.x?
3. strong parameters
Vá»i khai báo routes như dưá»i Äây, khi nháºn má»t URI "/courses/2/subjects/1", khẳng Äá»nh nà o là Äúng? Rails.application.routes.draw do resources :courses do resources :subjects endend
1. params[:id] = 1, params[:course_id] = 2
Äâu là khẳng Äá»nh Äúng vá» authenticity_token trong Rails?
2. authenticity_token is used to protect POST, PUT, and DELETE requests
có 1 mảng `ary = [1, nil, 2, 3, nil, 6]`, sau khi chạy câu lá»nh `ary.compact` thì giá trá» cá»§a `ary` là j?
3. [1, nil, 2, 3, nil, 6]
Dòng code nà o dưá»i Äây là không chÃnh xác trong Rails?
2. create_index :relationships, :follower_id
Lá»nh Äá» khá»i tạo má»t project rails má»i tên là "ittrain" là gì?
3. rails new ittrain
Lá»±a chá»n nà o dưá»i Äây không phải là thà nh phần cÆ¡ bản cá»§a Rails 3?
4. ActionWebService
File routes.rb ÄÆ°á»£c Äá»nh nghÄ©a như bên dưá»i. Helper method nà o dùng Äá» gá»i Äến action "comments#show"?Rails::Application.routes.draw do resources :message_boards do resources :comments endend
3. message_board_comment_url(@message_board, @comment)
Partial template nà o sẽ ÄÆ°á»£c render khi chạy lá»nh á» code 2?Code 1:class User < ActiveRecord::BaseendCode 2:<%= render User.all %>
1. app/views/users/_user.html.erb
Chá»n Äoạn code không phù hợp Äá» lưu và o database má»t user cho model ÄÆ°á»£c Äá»nh nghÄ©a dưá»i Äây.class User < ActiveRecord::Base validates :name, :presence => trueend
2. User.new(name: "John")
Chá»n dòng lá»nh Äá» sinh ra model User có hai trưá»ng string name và email
2. rails generate model user name:string email:string
Model ÄÆ°á»£c tạo ra bằng file migrate sau Äây có những trưá»ng nà o?class CreateUsers < ActiveRecord::Migration def self.up create_table :articles do |t| t.timestamps end end def self.down drop_table :articles endend
3. idãcreated_atãupdated_at
Äiá»n và o (1) dòng code Äá» validate Äá» dà i xâu cá»§a trưá»ng title trong bảng Article nằm trong 20 ký tá»±.class Article < ActiveRecord::Base __(1)__end
2. validates :title, length: {maximum: 20}
Chá»n má»t Äáp án Äúng khi nói vá» sá»± khác nhau giữaActiveRecord::Base#update_attributes!và ActiveRecord::Base#update_attributes
1. update_attributes! Khi validate lá»i thì trả vá» ngoại lá»
Äiá»n và o (1) dòng code thÃch hợp Äá» tạo ra má»t textbox.<%= form_for User.new do |f| %><%= __(1)__ %><% end %>
4. f.text_field :login
Khi chạy Äoạn code dưá»i, ná»i dung cá»§a email sẽ ÄÆ°á»£c lấy trong file nà o?class NoticeMailer < ActionMailer::Base def updated(recipient) mail :to => recipient.email endend
4. app/views/notice_mailer/updated.text.erb
Thứ tá»± load config nà o Äúng?
1. application.rb -> environment.rb -> initializes/.*
Chá»n câu Äúng
2. "&&" có ÄỠưu tiên cao hÆ¡n "||". "and" và "or" có ÄỠưu tiên bằng nhau.
Äâu là sá»± khác nhau giữa Date.today và Date.current
3. Date.today returns system date. Date.current returns system date applied with Rails' time zone.
Thứ tá»± Äúng cá»§a ActiveRecord callbacks:
1. before_validation, before_save, after_create, after_commit
Những khai nà o sau Äây ÄÆ°á»£c sá» dụng Äá» mô tả quan há» giữa các model?:
4. has_many :through, belongs_to, has_one, has_and_belongs_to_many
à nghÄ©a cá»§a "?" và "!" á» cuá»i tên cá»§a methods là gì?
3. Giúp dá» Äá»c code hÆ¡n. Có ý nghÄ©a ám chá» methods kết thúc bằng "?" sẽ trả vá» boolean, methods kết thúc bằng "!" sẽ thá»±c hiá»n thay Äá»i vÄ©nh viá» n.