diff --git a/actionview/lib/action_view/helpers/form_helper.rb b/actionview/lib/action_view/helpers/form_helper.rb index 71728f2dc8..07a53546f0 100644 --- a/actionview/lib/action_view/helpers/form_helper.rb +++ b/actionview/lib/action_view/helpers/form_helper.rb @@ -213,18 +213,18 @@ module FormHelper # In the examples above, the object to be created or edited was # represented by a symbol passed to +form_for+, and we noted that # a string can also be used equivalently. It is also possible, however, - # to pass a model object itself to +form_for+. For example, if @post + # to pass a model object itself to +form_for+. For example, if @article # is an existing record you wish to edit, you can create the form using # - # <%= form_for @post do |f| %> + # <%= form_for @article do |f| %> # ... # <% end %> # # This behaves in almost the same way as outlined previously, with a # couple of small exceptions. First, the prefix used to name the input # elements within the form (hence the key that denotes them in the +params+ - # hash) is actually derived from the object's _class_, e.g. params[:post] - # if the object's class is +Post+. However, this can be overwritten using + # hash) is actually derived from the object's _class_, e.g. params[:article] + # if the object's class is +Article+. However, this can be overwritten using # the :as option, e.g. - # # <%= form_for(@person, as: :client) do |f| %> @@ -236,15 +236,15 @@ module FormHelper # Secondly, the field values shown when the form is initially displayed # are taken from the attributes of the object passed to +form_for+, # regardless of whether the object is an instance - # variable. So, for example, if we had a _local_ variable +post+ + # variable. So, for example, if we had a _local_ variable +article+ # representing an existing record, # - # <%= form_for post do |f| %> + # <%= form_for article do |f| %> # ... # <% end %> # # would produce a form with fields whose initial state reflect the current - # values of the attributes of +post+. + # values of the attributes of +article+. # # === Resource-oriented style # @@ -256,49 +256,49 @@ module FormHelper # in config/routes.rb. In this case \Rails will simply infer the # appropriate URL from the record itself. For example, # - # <%= form_for @post do |f| %> + # <%= form_for @article do |f| %> # ... # <% end %> # # is then equivalent to something like: # - # <%= form_for @post, as: :post, url: post_path(@post), method: :patch, html: { class: "edit_post", id: "edit_post_45" } do |f| %> + # <%= form_for @article, as: :article, url: article_path(@article), method: :patch, html: { class: "edit_article", id: "edit_article_45" } do |f| %> # ... # <% end %> # # And for a new record # - # <%= form_for(Post.new) do |f| %> + # <%= form_for(Article.new) do |f| %> # ... # <% end %> # # is equivalent to something like: # - # <%= form_for @post, as: :post, url: posts_path, html: { class: "new_post", id: "new_post" } do |f| %> + # <%= form_for @article, as: :article, url: articles_path, html: { class: "new_article", id: "new_article" } do |f| %> # ... # <% end %> # # However you can still overwrite individual conventions, such as: # - # <%= form_for(@post, url: super_posts_path) do |f| %> + # <%= form_for(@article, url: super_articles_path) do |f| %> # ... # <% end %> # # You can omit the action attribute by passing url: false: # - # <%= form_for(@post, url: false) do |f| %> + # <%= form_for(@article, url: false) do |f| %> # ... # <% end %> # # You can also set the answer format, like this: # - # <%= form_for(@post, format: :json) do |f| %> + # <%= form_for(@article, format: :json) do |f| %> # ... # <% end %> # - # For namespaced routes, like +admin_post_url+: + # For namespaced routes, like +admin_article_url+: # - # <%= form_for([:admin, @post]) do |f| %> + # <%= form_for([:admin, @article]) do |f| %> # ... # <% end %> # @@ -334,7 +334,7 @@ module FormHelper # # Example: # - # <%= form_for(@post, remote: true) do |f| %> + # <%= form_for(@article, remote: true) do |f| %> # ... # <% end %> # @@ -350,7 +350,7 @@ module FormHelper # You can set data attributes directly by passing in a data hash, but all other HTML options must be wrapped in # the HTML key. Example: # - # <%= form_for(@post, data: { behavior: "autosave" }, html: { name: "go" }) do |f| %> + # <%= form_for(@article, data: { behavior: "autosave" }, html: { name: "go" }) do |f| %> # ... # <% end %> # @@ -368,12 +368,12 @@ module FormHelper # Some ORM systems do not use IDs on nested models so in this case you want to be able # to disable the hidden id. # - # In the following example the Post model has many Comments stored within it in a NoSQL database, + # In the following example the Article model has many Comments stored within it in a NoSQL database, # thus there is no primary key for comments. # # Example: # - # <%= form_for(@post) do |f| %> + # <%= form_for(@article) do |f| %> # <%= f.fields_for(:comments, include_id: false) do |cf| %> # ... # <% end %> @@ -485,12 +485,12 @@ def apply_form_for_options!(object, options) # :nodoc: # Creates a form tag based on mixing URLs, scopes, or models. # # # Using just a URL: - # <%= form_with url: posts_path do |form| %> + # <%= form_with url: articles_path do |form| %> # <%= form.text_field :title %> # <% end %> # # => - #
# # # With an intentionally empty URL: @@ -499,37 +499,36 @@ def apply_form_for_options!(object, options) # :nodoc: # <% end %> # # => # # # # Adding a scope prefixes the input field names: - # <%= form_with scope: :post, url: posts_path do |form| %> + # <%= form_with scope: :article, url: articles_path do |form| %> # <%= form.text_field :title %> # <% end %> # # => - # # # # Using a model infers both the URL and scope: - # <%= form_with model: Post.new do |form| %> + # <%= form_with model: Article.new do |form| %> # <%= form.text_field :title %> # <% end %> # # => - # # # # An existing model makes an update form and fills out field values: - # <%= form_with model: Post.first do |form| %> + # <%= form_with model: Article.first do |form| %> # <%= form.text_field :title %> # <% end %> # # => - # - # # # Though the fields don't have to correspond to model attributes: # <%= form_with model: Cat.new do |form| %> # <%= form.text_field :cats_dont_have_gills %> @@ -537,13 +536,13 @@ def apply_form_for_options!(object, options) # :nodoc: # <% end %> # # => # # # The parameters in the forms are accessible in controllers according to - # their name nesting. So inputs named +title+ and post[title] are - # accessible as params[:title] and params[:post][:title] + # their name nesting. So inputs named +title+ and article[title] are + # accessible as params[:title] and params[:article][:title] # respectively. # # For ease of comparison the examples above left out the submit button, @@ -559,25 +558,25 @@ def apply_form_for_options!(object, options) # :nodoc: # # So when passing such a model record, \Rails infers the URL and method. # - # <%= form_with model: @post do |form| %> + # <%= form_with model: @article do |form| %> # ... # <% end %> # # is then equivalent to something like: # - # <%= form_with scope: :post, url: post_path(@post), method: :patch do |form| %> + # <%= form_with scope: :article, url: article_path(@article), method: :patch do |form| %> # ... # <% end %> # # And for a new record # - # <%= form_with model: Post.new do |form| %> + # <%= form_with model: Article.new do |form| %> # ... # <% end %> # # is equivalent to something like: # - # <%= form_with scope: :post, url: posts_path do |form| %> + # <%= form_with scope: :article, url: articles_path do |form| %> # ... # <% end %> # @@ -606,7 +605,7 @@ def apply_form_for_options!(object, options) # :nodoc: # If the model is a new record a create form is generated, if an # existing record, however, an update form is generated. # Pass :scope or :url to override the defaults. - # E.g. turn params[:post] into params[:article]. + # E.g. turn params[:article] into params[:blog]. # * :authenticity_token - Authenticity token to use in the form. # Override with a custom authenticity token or pass false to # skip the authenticity token field altogether. @@ -639,14 +638,14 @@ def apply_form_for_options!(object, options) # :nodoc: # # When not passing a block, +form_with+ just generates an opening form tag. # - # <%= form_with(model: @post, url: super_posts_path) %> - # <%= form_with(model: @post, scope: :article) %> - # <%= form_with(model: @post, format: :json) %> - # <%= form_with(model: @post, authenticity_token: false) %> # Disables the token. + # <%= form_with(model: @article, url: super_articles_path) %> + # <%= form_with(model: @article, scope: :blog) %> + # <%= form_with(model: @article, format: :json) %> + # <%= form_with(model: @article, authenticity_token: false) %> # Disables the token. # - # For namespaced routes, like +admin_post_url+: + # For namespaced routes, like +admin_article_url+: # - # <%= form_with(model: [ :admin, @post ]) do |form| %> + # <%= form_with(model: [ :admin, @article ]) do |form| %> # ... # <% end %> # @@ -694,13 +693,13 @@ def apply_form_for_options!(object, options) # :nodoc: # You can set data attributes directly in a data hash, but HTML options # besides id and class must be wrapped in an HTML key: # - # <%= form_with(model: @post, data: { behavior: "autosave" }, html: { name: "go" }) do |form| %> + # <%= form_with(model: @article, data: { behavior: "autosave" }, html: { name: "go" }) do |form| %> # ... # <% end %> # # generates # - # @@ -712,10 +711,10 @@ def apply_form_for_options!(object, options) # :nodoc: # Some ORM systems do not use IDs on nested models so in this case you want to be able # to disable the hidden id. # - # In the following example the Post model has many Comments stored within it in a NoSQL database, + # In the following example the Article model has many Comments stored within it in a NoSQL database, # thus there is no primary key for comments. # - # <%= form_with(model: @post) do |form| %> + # <%= form_with(model: @article) do |form| %> # <%= form.fields(:comments, skip_id: true) do |fields| %> # ... # <% end %> @@ -1049,7 +1048,7 @@ def fields_for(record_name, record_object = nil, options = {}, &block) # # => # # # Using +fields+ with +form_with+: - # <%= form_with model: @post do |form| %> + # <%= form_with model: @article do |form| %> # <%= form.text_field :title %> # # <%= form.fields :comment do |fields| %> @@ -1097,58 +1096,58 @@ def fields(scope = nil, model: nil, **options, &block) # target labels for radio_button tags (where the value is used in the ID of the input tag). # # ==== Examples - # label(:post, :title) - # # => + # label(:article, :title) + # # => # # You can localize your labels based on model and attribute names. # For example you can define the following in your locale (e.g. en.yml) # # helpers: # label: - # post: + # article: # body: "Write your entire text here" # # Which then will result in # - # label(:post, :body) - # # => + # label(:article, :body) + # # => # # Localization can also be based purely on the translation of the attribute-name # (if you are using ActiveRecord): # # activerecord: # attributes: - # post: + # article: # cost: "Total cost" # #
#
- # label(:post, :cost)
- # # =>
+ # label(:article, :cost)
+ # # =>
#
- # label(:post, :title, "A short title")
- # # =>
+ # label(:article, :title, "A short title")
+ # # =>
#
- # label(:post, :title, "A short title", class: "title_label")
- # # =>
+ # label(:article, :title, "A short title", class: "title_label")
+ # # =>
#
- # label(:post, :privacy, "Public Post", value: "public")
- # # =>
+ # label(:article, :privacy, "Public Article", value: "public")
+ # # =>
#
- # label(:post, :cost) do |translation|
+ # label(:article, :cost) do |translation|
# content_tag(:span, translation, class: "cost_label")
# end
- # # =>
+ # # =>
#
- # label(:post, :cost) do |builder|
+ # label(:article, :cost) do |builder|
# content_tag(:span, builder.translation, class: "cost_label")
# end
- # # =>
+ # # =>
#
- # label(:post, :terms) do
+ # label(:article, :terms) do
# raw('Accept Terms.')
# end
- # # =>
+ # # =>
def label(object_name, method, content_or_options = nil, options = nil, &block)
Tags::Label.new(object_name, method, self, content_or_options, options).render(&block)
end
@@ -1159,14 +1158,14 @@ def label(object_name, method, content_or_options = nil, options = nil, &block)
# shown.
#
# ==== Examples
- # text_field(:post, :title, size: 20)
- # # =>
+ # text_field(:article, :title, size: 20)
+ # # =>
#
- # text_field(:post, :title, class: "create_input")
- # # =>
+ # text_field(:article, :title, class: "create_input")
+ # # =>
#
- # text_field(:post, :title, maxlength: 30, class: "title_input")
- # # =>
+ # text_field(:article, :title, maxlength: 30, class: "title_input")
+ # # =>
#
# text_field(:session, :user, onchange: "if ($('#session_user').val() === 'admin') { alert('Your login cannot be admin!'); }")
# # =>
@@ -1207,8 +1206,8 @@ def password_field(object_name, method, options = {})
# hidden_field(:signup, :pass_confirm)
# # =>
#
- # hidden_field(:post, :tag_list)
- # # =>
+ # hidden_field(:article, :tag_list)
+ # # =>
#
# hidden_field(:user, :token)
# # =>
@@ -1234,14 +1233,14 @@ def hidden_field(object_name, method, options = {})
# file_field(:user, :avatar)
# # =>
#
- # file_field(:post, :image, multiple: true)
- # # =>
+ # file_field(:article, :image, multiple: true)
+ # # =>
#
- # file_field(:post, :attached, accept: 'text/html')
- # # =>
+ # file_field(:article, :attached, accept: 'text/html')
+ # # =>
#
- # file_field(:post, :image, accept: 'image/png,image/gif,image/jpeg')
- # # =>
+ # file_field(:article, :image, accept: 'image/png,image/gif,image/jpeg')
+ # # =>
#
# file_field(:attachment, :file, class: 'file_input')
# # =>
@@ -1256,9 +1255,9 @@ def file_field(object_name, method, options = {})
# hash with +options+.
#
# ==== Examples
- # text_area(:post, :body, cols: 20, rows: 40)
- # # =>