<%= render partial: "nav", selected: "about"}%>
<%= render partial: "nav", local_variables: {selected: "about"} %>
<%= render partial: "nav", locals: {selected: "about"}
before_action
:get_feature
运行?skip_before_action :get_feature
skip :get_feature, except: []
prevent_action :get_feature
:redis_cache_store
form_tag
和form_for
之间的差异?form_tag
方法用于基本表单,而form_for
方法用于包含文件上传的多部分表单。 form_tag
方法用于HTTP请求,而form_for
方法用于AJAX请求。 form_tag
方法通常期望URL作为其第一个参数,而form_for
方法通常期望一个模型对象。 form_tag
方法在运行时评估,而form_for
方法预编译并缓存。 before_action
(以前称为before_filter
)是什么?ActiveSupport::Concern
RailsHelper.CommonClass
ActiveJob::Mixin
ActiveSupport::Module
PUT
和PATCH
REST HTTP
动词的路由?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
和 :documentable_type
列。 :documentable
和 :type
列。 :polymorphic_type
列。 my_model.errors[:field]
my_model.get_errors_for(:field)
my_model.field.error
my_model.all_errors.select(:field)
class DocumentsController < ApplicationController before_action :require_login def index @documents = Document.visible.sorted end end
:index
未列为before_action
的参数。 require_login
方法将在运行索引操作之前自动登录用户。 require_login
方法调用了render或redirect_to
,则不会运行索引操作。 <%= 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
定义一个错误消息,消息为“This address is invalid”?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)
,哪个陈述预期将会是_错误_的?class DocumentsController < ApplicationController before_action :require_login def index @documents = Document.visible.sorted end end
:index
未列为before_action
的参数。 require_login
方法将在运行索引操作之前自动登录用户。 require_login
方法调用了render或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: {}
coffee_orders
的表的现有数据库。为了使用该表,ActiveRecord模型应该命名为什么?CoffeeOrders
Coffee_Orders
Coffee_Order
CoffeeOrder