
Rails Forms
form_with, model forms, form_for legacy, strong parameters, nested attributes, file uploads
1What is the recommended form helper in Rails 5.1+ for creating forms?
What is the recommended form helper in Rails 5.1+ for creating forms?
Câu trả lời
form_with is the unified helper introduced in Rails 5.1 that replaces form_for and form_tag. It generates forms with remote: true by default (AJAX requests) and simplifies syntax by automatically detecting if a model object is passed. This unification reduces confusion between the two older helpers and provides a more consistent API.
2What is the difference between form_with model: @user and form_with url: users_path?
What is the difference between form_with model: @user and form_with url: users_path?
Câu trả lời
With model: @user, Rails automatically determines the URL and HTTP method based on the object's state (new_record? or persisted?). For a new record, it uses POST to users_path, for an existing one, PATCH to user_path(@user). With url: users_path, the URL and appropriate HTTP method must be specified manually.
3How to disable the default AJAX submissions of form_with to get a classic HTML submission?
How to disable the default AJAX submissions of form_with to get a classic HTML submission?
Câu trả lời
By default, form_with generates forms with data-remote='true' that send AJAX requests. To get a traditional HTML submission with page reload, local: true must be added. Starting from Rails 6.1, the default behavior can be configured globally via config.action_view.form_with_generates_remote_forms.
What is the role of strong parameters in the context of Rails forms?
How to correctly define a strong parameters method for an Article model with title and content?
+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
Views & ERB Templates
ActiveRecord Associations
Advanced ActiveRecord Queries
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í