render trong một view, làm sao để truyền biến cục bộ để hiển thị?<%= render partial: "nav", selected: "about"}%> <%= render partial: "nav", local_variables: {selected: "about"} %> <%= render partial: "nav", locals: {selected: "about"} before_action của controller cha với tên :get_feature?skip_before_action :get_feature skip :get_feature, except: [] prevent_action :get_feature :redis_cache_store form_tag và form_for?form_tag dành cho các biểu mẫu cơ bản, trong khi phương thức form_for dành cho các biểu mẫu nhiều phần bao gồm tải lên tập tin. form_tag dùng cho các yêu cầu HTTP, trong khi phương thức form_for dùng cho các yêu cầu AJAX. form_tag thường mong đợi một URL làm đối số đầu tiên, trong khi phương thức form_for thường mong đợi một đối tượng mẫu. form_tag được đánh giá tại thời điểm chạy, trong khi phương thức form_for được biên dịch trước và được lưu trữ vào bộ nhớ cache. before_action (trước đây là before_filter) là gì?ActiveSupport::Concern RailsHelper.CommonClass ActiveJob::Mixin ActiveSupport::Module PUT và PATCH?put :items, include: patch put 'items', to: 'items#update' match 'items', to 'items#update', via: [:put, :patch] match :items, using: put && patch Product.where("name = #{@keyword}") Product.where("name = " << @keyword} Product.where("name = ?", @keyword Product.where("name = " + h(@keyword) class Document < ActiveRecord::Base belongs_to :documentable, polymorphic: true end class Product < ActiveRecord::Base has_many :documents, as: :documentable end class Service < ActiveRecord::Base has_many :documents, as: :documentable end
:type. :documentable_id và :documentable_type. :documentable và :type. :polymorphic_type. ]`
my_model.get_errors_for(:field) my_model.field.error my_model.all_errors.select(:field) id là khóa chính, câu nào sẽ trả về chỉ một đối tượng có last_name là "Cordero"?-------------------------------
| id | first_name | last_name |
|----|------------|-----------|
| 1 | Alice | Anderson |
| 2 | Bob | Buckner |
| 3 | Carrie | Cordero |
| 4 | Devon | Dupre |
| 5 | Carrie | Eastman |
-------------------------------
User.where(first_name: "Carrie") User.not.where(id: [1, 2, 4, 5]) User.find_by(first_name: "Cordero") User.find(3) <%= select_tag(@products) %> <%= collection_select(@products) %> <select name="product_id"> <%= @products.each do |product| %> <option value="<%= product.id %>"/> <% end %></select> <%= collection_select(:product, :product_id, Product.all, :id, :name) %> address với thông điệp "Địa chỉ này không hợp lệ"?model.errors = This address is invalid errors(model, :address) << "This address is invalid" display_error_for(model, :address, "This address is invalid") model.errors[:address] << "This address is invalid" product_path(@product), câu nào sẽ được mong đợi là sai?class DocumentsController < ApplicationController before_action :require_login def index @documents = Document.visible.sorted end end
:index không được liệt kê là một đối số cho before_action. require_login sẽ tự động đăng nhập người dùng trước khi chạy hành động index. require_login gọi render hoặc redirect_to. render partial: 'shared/menu', cached: true render_with_cache partial: 'shared/menu' render partial: 'shared/menu' render partial: 'shared/menu', cached_with_variables: {} build new create save coffee_orders. Mô hình ActiveRecord sẽ mang tên gì để sử dụng bảng đó?CoffeeOrders Coffee_Orders Coffee_Order CoffeeOrder