Browse files

More Ruby 1.9 hash syntax.

  • Loading branch information...
1 parent e1e4b1d commit e1dd284614d137f47a4f8a4ce79316845f9df295 @rafaelfranca rafaelfranca committed Oct 6, 2012
Showing with 47 additions and 52 deletions.
  1. +47 −52 actionpack/lib/action_view/helpers/form_helper.rb
View
99 actionpack/lib/action_view/helpers/form_helper.rb
@@ -207,7 +207,7 @@ module FormHelper
# if the object's class is +Post+. However, this can be overwritten using
# the <tt>:as</tt> option, e.g. -
#
- # <%= form_for(@person, :as => :client) do |f| %>
+ # <%= form_for(@person, as: :client) do |f| %>
# ...
# <% end %>
#
@@ -242,7 +242,7 @@ module FormHelper
#
# is then equivalent to something like:
#
- # <%= form_for @post, :as => :post, :url => post_path(@post), :method => :put, :html => { :class => "edit_post", :id => "edit_post_45" } do |f| %>
+ # <%= form_for @post, as: :post, url: post_path(@post), method: :put, html: { class: "edit_post", id: "edit_post_45" } do |f| %>
# ...
# <% end %>
#
@@ -254,19 +254,19 @@ module FormHelper
#
# is equivalent to something like:
#
- # <%= form_for @post, :as => :post, :url => posts_path, :html => { :class => "new_post", :id => "new_post" } do |f| %>
+ # <%= form_for @post, as: :post, url: posts_path, html: { class: "new_post", id: "new_post" } do |f| %>
# ...
# <% end %>
#
# However you can still overwrite individual conventions, such as:
#
- # <%= form_for(@post, :url => super_posts_path) do |f| %>
+ # <%= form_for(@post, url: super_posts_path) do |f| %>
# ...
# <% end %>
#
# You can also set the answer format, like this:
#
- # <%= form_for(@post, :format => :json) do |f| %>
+ # <%= form_for(@post, format: :json) do |f| %>
# ...
# <% end %>
#
@@ -290,7 +290,7 @@ module FormHelper
#
# You can force the form to use the full array of HTTP verbs by setting
#
- # :method => (:get|:post|:patch|:put|:delete)
+ # method: (:get|:post|:patch|:put|:delete)
#
# in the options hash. If the verb is not GET or POST, which are natively
# supported by HTML forms, the form will be set to POST and a hidden input
@@ -300,7 +300,7 @@ module FormHelper
#
# Specifying:
#
- # :remote => true
+ # remote: true
#
# in the options hash creates a form that will allow the unobtrusive JavaScript drivers to modify its
# behavior. The expected default behavior is an XMLHttpRequest in the background instead of the regular
@@ -310,7 +310,7 @@ module FormHelper
#
# Example:
#
- # <%= form_for(@post, :remote => true) do |f| %>
+ # <%= form_for(@post, remote: true) do |f| %>
# ...
# <% end %>
#
@@ -354,7 +354,7 @@ module FormHelper
# Example:
#
# <%= form_for(@post) do |f| %>
- # <%= f.fields_for(:comments, :include_id => false) do |cf| %>
+ # <%= f.fields_for(:comments, include_id: false) do |cf| %>
# ...
# <% end %>
# <% end %>
@@ -366,7 +366,7 @@ module FormHelper
# custom builder. For example, let's say you made a helper to
# automatically add labels to form inputs.
#
- # <%= form_for @person, :url => { :action => "create" }, :builder => LabellingFormBuilder do |f| %>
+ # <%= form_for @person, url: { action: "create" }, builder: LabellingFormBuilder do |f| %>
# <%= f.text_field :first_name %>
# <%= f.text_field :last_name %>
# <%= f.text_area :biography %>
@@ -390,7 +390,7 @@ module FormHelper
#
# def labelled_form_for(record_or_name_or_array, *args, &proc)
# options = args.extract_options!
- # form_for(record_or_name_or_array, *(args << options.merge(:builder => LabellingFormBuilder)), &proc)
+ # form_for(record_or_name_or_array, *(args << options.merge(builder: LabellingFormBuilder)), &proc)
# end
#
# If you don't need to attach a form to a model instance, then check out
@@ -403,13 +403,13 @@ module FormHelper
#
# To set an authenticity token you need to pass an <tt>:authenticity_token</tt> parameter
#
- # <%= form_for @invoice, :url => external_url, :authenticity_token => 'external_token' do |f|
+ # <%= form_for @invoice, url: external_url, authenticity_token: 'external_token' do |f|
# ...
# <% end %>
#
# If you don't want to an authenticity token field be rendered at all just pass <tt>false</tt>:
#
- # <%= form_for @invoice, :url => external_url, :authenticity_token => false do |f|
+ # <%= form_for @invoice, url: external_url, authenticity_token: false do |f|
# ...
# <% end %>
def form_for(record, options = {}, &proc)
@@ -435,7 +435,7 @@ def form_for(record, options = {}, &proc)
builder = options[:parent_builder] = instantiate_builder(object_name, object, options)
fields_for = fields_for(object_name, object, options, &proc)
- default_options = builder.multipart? ? { :multipart => true } : {}
+ default_options = builder.multipart? ? { multipart: true } : {}
default_options.merge!(options.delete(:html))
form_tag(options.delete(:url) || {}, default_options) { fields_for }
@@ -447,12 +447,12 @@ def apply_form_for_options!(record, object, options) #:nodoc:
as = options[:as]
action, method = object.respond_to?(:persisted?) && object.persisted? ? [:edit, :patch] : [:new, :post]
options[:html].reverse_merge!(
- :class => as ? "#{action}_#{as}" : dom_class(object, action),
- :id => as ? "#{action}_#{as}" : [options[:namespace], dom_id(object, action)].compact.join("_").presence,
- :method => method
+ class: as ? "#{action}_#{as}" : dom_class(object, action),
+ id: as ? "#{action}_#{as}" : [options[:namespace], dom_id(object, action)].compact.join("_").presence,
+ method: method
)
- options[:url] ||= polymorphic_path(record, :format => options.delete(:format))
+ options[:url] ||= polymorphic_path(record, format: options.delete(:format))
end
private :apply_form_for_options!
@@ -578,7 +578,7 @@ def apply_form_for_options!(record, object, options) #:nodoc:
#
# class Person < ActiveRecord::Base
# has_one :address
- # accepts_nested_attributes_for :address, :allow_destroy => true
+ # accepts_nested_attributes_for :address, allow_destroy: true
# end
#
# Now, when you use a form element with the <tt>_destroy</tt> parameter,
@@ -674,7 +674,7 @@ def apply_form_for_options!(record, object, options) #:nodoc:
#
# class Person < ActiveRecord::Base
# has_many :projects
- # accepts_nested_attributes_for :projects, :allow_destroy => true
+ # accepts_nested_attributes_for :projects, allow_destroy: true
# end
#
# This will allow you to specify which models to destroy in the
@@ -747,10 +747,10 @@ def fields_for(record_name, record_object = nil, options = {}, &block)
# label(:post, :title, "A short title")
# # => <label for="post_title">A short title</label>
#
- # label(:post, :title, "A short title", :class => "title_label")
+ # label(:post, :title, "A short title", class: "title_label")
# # => <label for="post_title" class="title_label">A short title</label>
#
- # label(:post, :privacy, "Public Post", :value => "public")
+ # label(:post, :privacy, "Public Post", value: "public")
# # => <label for="post_privacy_public">Public Post</label>
#
# label(:post, :terms) do
@@ -766,18 +766,17 @@ def label(object_name, method, content_or_options = nil, options = nil, &block)
# shown.
#
# ==== Examples
- # text_field(:post, :title, :size => 20)
+ # text_field(:post, :title, size: 20)
# # => <input type="text" id="post_title" name="post[title]" size="20" value="#{@post.title}" />
#
- # text_field(:post, :title, :class => "create_input")
+ # text_field(:post, :title, class: "create_input")
# # => <input type="text" id="post_title" name="post[title]" value="#{@post.title}" class="create_input" />
#
- # text_field(:session, :user, :onchange => "if $('session[user]').value == 'admin' { alert('Your login can not be admin!'); }")
+ # text_field(:session, :user, onchange: "if $('session[user]').value == 'admin' { alert('Your login can not be admin!'); }")
# # => <input type="text" id="session_user" name="session[user]" value="#{@session.user}" onchange = "if $('session[user]').value == 'admin' { alert('Your login can not be admin!'); }"/>
#
- # text_field(:snippet, :code, :size => 20, :class => 'code_input')
+ # text_field(:snippet, :code, size: 20, class: 'code_input')
# # => <input type="text" id="snippet_code" name="snippet[code]" size="20" value="#{@snippet.code}" class="code_input" />
- #
def text_field(object_name, method, options = {})
Tags::TextField.new(object_name, method, self, options).render
end
@@ -788,18 +787,17 @@ def text_field(object_name, method, options = {})
# shown. For security reasons this field is blank by default; pass in a value via +options+ if this is not desired.
#
# ==== Examples
- # password_field(:login, :pass, :size => 20)
+ # password_field(:login, :pass, size: 20)
# # => <input type="password" id="login_pass" name="login[pass]" size="20" />
#
- # password_field(:account, :secret, :class => "form_input", :value => @account.secret)
+ # password_field(:account, :secret, class: "form_input", value: @account.secret)
# # => <input type="password" id="account_secret" name="account[secret]" value="#{@account.secret}" class="form_input" />
#
- # password_field(:user, :password, :onchange => "if $('user[password]').length > 30 { alert('Your password needs to be shorter!'); }")
+ # password_field(:user, :password, onchange: "if $('user[password]').length > 30 { alert('Your password needs to be shorter!'); }")
# # => <input type="password" id="user_password" name="user[password]" onchange = "if $('user[password]').length > 30 { alert('Your password needs to be shorter!'); }"/>
#
- # password_field(:account, :pin, :size => 20, :class => 'form_input')
+ # password_field(:account, :pin, size: 20, class: 'form_input')
# # => <input type="password" id="account_pin" name="account[pin]" size="20" class="form_input" />
- #
def password_field(object_name, method, options = {})
Tags::PasswordField.new(object_name, method, self, options).render
end
@@ -833,12 +831,11 @@ def hidden_field(object_name, method, options = {})
# file_field(:user, :avatar)
# # => <input type="file" id="user_avatar" name="user[avatar]" />
#
- # file_field(:post, :attached, :accept => 'text/html')
+ # file_field(:post, :attached, accept: 'text/html')
# # => <input accept="text/html" type="file" id="post_attached" name="post[attached]" />
#
- # file_field(:attachment, :file, :class => 'file_input')
+ # file_field(:attachment, :file, class: 'file_input')
# # => <input type="file" id="attachment_file" name="attachment[file]" class="file_input" />
- #
def file_field(object_name, method, options = {})
Tags::FileField.new(object_name, method, self, options).render
end
@@ -848,22 +845,22 @@ def file_field(object_name, method, options = {})
# hash with +options+.
#
# ==== Examples
- # text_area(:post, :body, :cols => 20, :rows => 40)
+ # text_area(:post, :body, cols: 20, rows: 40)
# # => <textarea cols="20" rows="40" id="post_body" name="post[body]">
# # #{@post.body}
# # </textarea>
#
- # text_area(:comment, :text, :size => "20x30")
+ # text_area(:comment, :text, size: "20x30")
# # => <textarea cols="20" rows="30" id="comment_text" name="comment[text]">
# # #{@comment.text}
# # </textarea>
#
- # text_area(:application, :notes, :cols => 40, :rows => 15, :class => 'app_input')
+ # text_area(:application, :notes, cols: 40, rows: 15, class: 'app_input')
# # => <textarea cols="40" rows="15" id="application_notes" name="application[notes]" class="app_input">
# # #{@application.notes}
# # </textarea>
#
- # text_area(:entry, :body, :size => "20x20", :disabled => 'disabled')
+ # text_area(:entry, :body, size: "20x20", disabled: 'disabled')
# # => <textarea cols="20" rows="20" id="entry_body" name="entry[body]" disabled="disabled">
# # #{@entry.body}
# # </textarea>
@@ -902,7 +899,7 @@ def text_area(object_name, method, options = {})
# Unfortunately that workaround does not work when the check box goes
# within an array-like parameter, as in
#
- # <%= fields_for "project[invoice_attributes][]", invoice, :index => nil do |form| %>
+ # <%= fields_for "project[invoice_attributes][]", invoice, index: nil do |form| %>
# <%= form.check_box :paid %>
# ...
# <% end %>
@@ -924,10 +921,9 @@ def text_area(object_name, method, options = {})
# # => <input name="puppy[gooddog]" type="hidden" value="no" />
# # <input type="checkbox" id="puppy_gooddog" name="puppy[gooddog]" value="yes" />
#
- # check_box("eula", "accepted", { :class => 'eula_check' }, "yes", "no")
+ # check_box("eula", "accepted", { class: 'eula_check' }, "yes", "no")
# # => <input name="eula[accepted]" type="hidden" value="no" />
# # <input type="checkbox" class="eula_check" id="eula_accepted" name="eula[accepted]" value="yes" />
- #
def check_box(object_name, method, options = {}, checked_value = "1", unchecked_value = "0")
Tags::CheckBox.new(object_name, method, self, checked_value, unchecked_value, options).render
end
@@ -936,7 +932,7 @@ def check_box(object_name, method, options = {}, checked_value = "1", unchecked_
# assigned to the template (identified by +object+). If the current value of +method+ is +tag_value+ the
# radio button will be checked.
#
- # To force the radio button to be checked pass <tt>:checked => true</tt> in the
+ # To force the radio button to be checked pass <tt>checked: true</tt> in the
# +options+ hash. You may pass HTML options there as well.
#
# # Let's say that @post.category returns "rails":
@@ -957,7 +953,6 @@ def radio_button(object_name, method, tag_value, options = {})
#
# color_field("car", "color")
# # => <input id="car_color" name="car[color]" type="color" value="#000000" />
- #
def color_field(object_name, method, options = {})
Tags::ColorField.new(object_name, method, self, options).render
end
@@ -968,18 +963,18 @@ def color_field(object_name, method, options = {})
#
# search_field(:user, :name)
# # => <input id="user_name" name="user[name]" type="search" />
- # search_field(:user, :name, :autosave => false)
+ # search_field(:user, :name, autosave: false)
# # => <input autosave="false" id="user_name" name="user[name]" type="search" />
- # search_field(:user, :name, :results => 3)
+ # search_field(:user, :name, results: 3)
# # => <input id="user_name" name="user[name]" results="3" type="search" />
# # Assume request.host returns "www.example.com"
- # search_field(:user, :name, :autosave => true)
+ # search_field(:user, :name, autosave: true)
# # => <input autosave="com.example.www" id="user_name" name="user[name]" results="10" type="search" />
- # search_field(:user, :name, :onsearch => true)
+ # search_field(:user, :name, onsearch: true)
# # => <input id="user_name" incremental="true" name="user[name]" onsearch="true" type="search" />
- # search_field(:user, :name, :autosave => false, :onsearch => true)
+ # search_field(:user, :name, autosave: false, onsearch: true)
# # => <input autosave="false" id="user_name" incremental="true" name="user[name]" onsearch="true" type="search" />
- # search_field(:user, :name, :autosave => true, :onsearch => true)
+ # search_field(:user, :name, autosave: true, onsearch: true)
# # => <input autosave="com.example.www" id="user_name" incremental="true" name="user[name]" onsearch="true" results="10" type="search" />
def search_field(object_name, method, options = {})
Tags::SearchField.new(object_name, method, self, options).render
@@ -1351,7 +1346,7 @@ def emitted_hidden_id?
private
def objectify_options(options)
- @default_options.merge(options.merge(:object => @object))
+ @default_options.merge(options.merge(object: @object))
end
def submit_default_value
@@ -1369,7 +1364,7 @@ def submit_default_value
defaults << :"helpers.submit.#{key}"
defaults << "#{key.to_s.humanize} #{model}"
- I18n.t(defaults.shift, :model => model, :default => defaults)
+ I18n.t(defaults.shift, model: model, default: defaults)
end
def nested_attributes_association?(association_name)

0 comments on commit e1dd284

Please sign in to comment.