
Views & ERB Templates
ERB syntax, layouts, partials, helpers, form_with, link_to, content_for, yield
1What is the difference between ERB tags <%= %> and <% %> ?
What is the difference between ERB tags <%= %> and <% %> ?
Câu trả lời
The <%= %> tag evaluates Ruby code and outputs the result to HTML, while <% %> executes code without displaying anything. For example, <%= @user.name %> displays the user's name, whereas <% if @user.admin? %> only executes the condition. This distinction is fundamental for controlling what appears in the rendered page.
2Which ERB tag allows adding a comment that will not be visible in the generated HTML?
Which ERB tag allows adding a comment that will not be visible in the generated HTML?
Câu trả lời
The <%# %> tag allows adding comments in ERB templates that will not be included in the final HTML. Unlike HTML comments <!-- -->, these comments are completely ignored during rendering and never appear in the source code sent to the browser, which is useful for internal notes.
3Where is the default layout of a Rails application located?
Where is the default layout of a Rails application located?
Câu trả lời
The default layout of a Rails application is located in app/views/layouts/application.html.erb. This file contains the common HTML structure for all pages, including head and body tags, and the yield call that indicates where specific view content will be inserted. Controllers can specify a different layout if needed.
What is the purpose of the yield keyword in a Rails layout?
How to render a partial named _header.html.erb in a Rails view?
+17 câu hỏi phỏng vấn
Các chủ đề phỏng vấn Ruby on Rails khác
Ruby Basics
Ruby Object-Oriented Programming
Rails Fundamentals
Routing & Controllers
ActiveRecord Basics
ActiveRecord Associations
Advanced ActiveRecord Queries
Rails Forms
Authentication & Authorization
Modern Asset Pipeline & Frontend
Rails API Mode
Testing with RSpec
ActiveJob & Background Jobs
ActionCable & WebSockets
ActionMailer
ActiveStorage
Caching Strategies
Advanced Migrations
Rails Engines & Modular Apps
Performance Optimization
Rails Design Patterns
Ruby Metaprogramming
Rails Security
GraphQL with Rails
Deployment & Production
Monitoring & Logging
Rails Upgrade Strategies
Nắm vững Ruby on Rails cho lần phỏng vấn tiếp theo
Truy cập tất cả câu hỏi, flashcards, bài kiểm tra kỹ thuật, bài tập code review và mô phỏng phỏng vấn.
Bắt đầu miễn phí