aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_view/helpers/url_helper.rb
diff options
context:
space:
mode:
authorRafael Mendonça França <rafaelmfranca@gmail.com>2012-10-06 22:00:06 -0300
committerRafael Mendonça França <rafaelmfranca@gmail.com>2012-10-06 22:01:32 -0300
commitd76ef6fa6cd34f4c7023706e8b8b4eb8a6a03b88 (patch)
tree10b3e6a374e4c5d75405a80239100a5b76658a15 /actionpack/lib/action_view/helpers/url_helper.rb
parent93d22512f9f8b753af8fe3f9148bba7cc05654ce (diff)
downloadrails-d76ef6fa6cd34f4c7023706e8b8b4eb8a6a03b88.tar.gz
rails-d76ef6fa6cd34f4c7023706e8b8b4eb8a6a03b88.tar.bz2
rails-d76ef6fa6cd34f4c7023706e8b8b4eb8a6a03b88.zip
Update some code styles.
* Uses the Ruby 1.9 hash syntax * Avoid escaping " inside string using the %{} syntax
Diffstat (limited to 'actionpack/lib/action_view/helpers/url_helper.rb')
-rw-r--r--actionpack/lib/action_view/helpers/url_helper.rb98
1 files changed, 48 insertions, 50 deletions
diff --git a/actionpack/lib/action_view/helpers/url_helper.rb b/actionpack/lib/action_view/helpers/url_helper.rb
index e8b3b14265..5105d0e585 100644
--- a/actionpack/lib/action_view/helpers/url_helper.rb
+++ b/actionpack/lib/action_view/helpers/url_helper.rb
@@ -46,7 +46,6 @@ module ActionView
end
protected :_back_url
-
# Creates a link tag of the given +name+ using a URL created by the set of +options+.
# See the valid options in the documentation for +url_for+. It's also possible to
# pass a String instead of an options hash, which generates a link tag that uses the
@@ -115,7 +114,7 @@ module ActionView
#
# in place of the older more verbose, non-resource-oriented
#
- # link_to "Profile", :controller => "profiles", :action => "show", :id => @profile
+ # link_to "Profile", controller: "profiles", action: "show", id: @profile
# # => <a href="/profiles/show/1">Profile</a>
#
# Similarly,
@@ -125,7 +124,7 @@ module ActionView
#
# is better than
#
- # link_to "Profiles", :controller => "profiles"
+ # link_to "Profiles", controller: "profiles"
# # => <a href="/profiles">Profiles</a>
#
# You can use a block as well if your link target is hard to fit into the name parameter. ERB example:
@@ -139,38 +138,38 @@ module ActionView
#
# Classes and ids for CSS are easy to produce:
#
- # link_to "Articles", articles_path, :id => "news", :class => "article"
+ # link_to "Articles", articles_path, id: "news", class: "article"
# # => <a href="/articles" class="article" id="news">Articles</a>
#
# Be careful when using the older argument style, as an extra literal hash is needed:
#
- # link_to "Articles", { :controller => "articles" }, :id => "news", :class => "article"
+ # link_to "Articles", { controller: "articles" }, id: "news", class: "article"
# # => <a href="/articles" class="article" id="news">Articles</a>
#
# Leaving the hash off gives the wrong link:
#
- # link_to "WRONG!", :controller => "articles", :id => "news", :class => "article"
+ # link_to "WRONG!", controller: "articles", id: "news", class: "article"
# # => <a href="/articles/index/news?class=article">WRONG!</a>
#
# +link_to+ can also produce links with anchors or query strings:
#
- # link_to "Comment wall", profile_path(@profile, :anchor => "wall")
+ # link_to "Comment wall", profile_path(@profile, anchor: "wall")
# # => <a href="/profiles/1#wall">Comment wall</a>
#
- # link_to "Ruby on Rails search", :controller => "searches", :query => "ruby on rails"
+ # link_to "Ruby on Rails search", controller: "searches", query: "ruby on rails"
# # => <a href="/searches?query=ruby+on+rails">Ruby on Rails search</a>
#
- # link_to "Nonsense search", searches_path(:foo => "bar", :baz => "quux")
+ # link_to "Nonsense search", searches_path(foo: "bar", baz: "quux")
# # => <a href="/searches?foo=bar&amp;baz=quux">Nonsense search</a>
#
# The only option specific to +link_to+ (<tt>:method</tt>) is used as follows:
#
- # link_to("Destroy", "http://www.example.com", :method => :delete)
+ # link_to("Destroy", "http://www.example.com", method: :delete)
# # => <a href='http://www.example.com' rel="nofollow" data-method="delete">Destroy</a>
#
# You can also use custom data attributes using the <tt>:data</tt> option:
#
- # link_to "Visit Other Site", "http://www.rubyonrails.org/", :data => { :confirm => "Are you sure?" }
+ # link_to "Visit Other Site", "http://www.rubyonrails.org/", data: { confirm: "Are you sure?" }
# # => <a href="http://www.rubyonrails.org/" data-confirm="Are you sure?"">Visit Other Site</a>
def link_to(name = nil, options = nil, html_options = nil, &block)
html_options, options = options, name if block_given?
@@ -197,7 +196,7 @@ module ActionView
# the form submission and input element behavior using +html_options+.
# This method accepts the <tt>:method</tt> modifier described in the +link_to+ documentation.
# If no <tt>:method</tt> modifier is given, it will default to performing a POST operation.
- # You can also disable the button by passing <tt>:disabled => true</tt> in +html_options+.
+ # You can also disable the button by passing <tt>disabled: true</tt> in +html_options+.
# If you are using RESTful routes, you can pass the <tt>:method</tt>
# to change the HTTP verb used to submit the form.
#
@@ -226,7 +225,7 @@ module ActionView
# by the unobtrusive JavaScript driver.
#
# ==== Examples
- # <%= button_to "New", :action => "new" %>
+ # <%= button_to "New", action: "new" %>
# # => "<form method="post" action="/controller/new" class="button_to">
# # <div><input value="New" type="submit" /></div>
# # </form>"
@@ -242,13 +241,13 @@ module ActionView
# # </div>
# # </form>"
#
- # <%= button_to "New", :action => "new", :form_class => "new-thing" %>
+ # <%= button_to "New", action: "new", form_class: "new-thing" %>
# # => "<form method="post" action="/controller/new" class="new-thing">
# # <div><input value="New" type="submit" /></div>
# # </form>"
#
#
- # <%= button_to "Create", :action => "create", :remote => true, :form => { "data-type" => "json" } %>
+ # <%= button_to "Create", action: "create", remote: true, form: { "data-type" => "json" } %>
# # => "<form method="post" action="/images/create" class="button_to" data-remote="true" data-type="json">
# # <div>
# # <input value="Create" type="submit" />
@@ -257,8 +256,8 @@ module ActionView
# # </form>"
#
#
- # <%= button_to "Delete Image", { :action => "delete", :id => @image.id },
- # :method => :delete, :data => { :confirm => "Are you sure?" } %>
+ # <%= button_to "Delete Image", { action: "delete", id: @image.id },
+ # method: :delete, data: { confirm: "Are you sure?" } %>
# # => "<form method="post" action="/images/delete/1" class="button_to">
# # <div>
# # <input type="hidden" name="_method" value="delete" />
@@ -269,7 +268,7 @@ module ActionView
#
#
# <%= button_to('Destroy', 'http://www.example.com',
- # :method => "delete", :remote => true, :data => { :confirm' => 'Are you sure?', :disable_with => 'loading...' }) %>
+ # method: "delete", remote: true, data: { confirm: 'Are you sure?', disable_with: 'loading...' }) %>
# # => "<form class='button_to' method='post' action='http://www.example.com' data-remote='true'>
# # <div>
# # <input name='_method' value='delete' type='hidden' />
@@ -295,7 +294,7 @@ module ActionView
form_method = method == 'get' ? 'get' : 'post'
form_options = html_options.delete('form') || {}
form_options[:class] ||= html_options.delete('form_class') || 'button_to'
- form_options.merge!(:method => form_method, :action => url)
+ form_options.merge!(method: form_method, action: url)
form_options.merge!("data-remote" => "true") if remote
request_token_tag = form_method == 'post' ? token_tag : ''
@@ -314,7 +313,6 @@ module ActionView
content_tag('form', content_tag('div', inner_tags), form_options)
end
-
# Creates a link tag of the given +name+ using a URL created by the set of
# +options+ unless the current request URI is the same as the links, in
# which case only the name is returned (or the given block is yielded, if
@@ -326,8 +324,8 @@ module ActionView
# Let's say you have a navigation menu...
#
# <ul id="navbar">
- # <li><%= link_to_unless_current("Home", { :action => "index" }) %></li>
- # <li><%= link_to_unless_current("About Us", { :action => "about" }) %></li>
+ # <li><%= link_to_unless_current("Home", { action: "index" }) %></li>
+ # <li><%= link_to_unless_current("About Us", { action: "about" }) %></li>
# </ul>
#
# If in the "about" action, it will render...
@@ -349,8 +347,8 @@ module ActionView
# "Go Back" link instead of a link to the comments page, we could do something like this...
#
# <%=
- # link_to_unless_current("Comment", { :controller => "comments", :action => "new" }) do
- # link_to("Go back", { :controller => "posts", :action => "index" })
+ # link_to_unless_current("Comment", { controller: "comments", action: "new" }) do
+ # link_to("Go back", { controller: "posts", action: "index" })
# end
# %>
def link_to_unless_current(name, options = {}, html_options = {}, &block)
@@ -364,13 +362,13 @@ module ActionView
# accepts the name or the full argument list for +link_to_unless+.
#
# ==== Examples
- # <%= link_to_unless(@current_user.nil?, "Reply", { :action => "reply" }) %>
+ # <%= link_to_unless(@current_user.nil?, "Reply", { action: "reply" }) %>
# # If the user is logged in...
# # => <a href="/controller/reply/">Reply</a>
#
# <%=
- # link_to_unless(@current_user.nil?, "Reply", { :action => "reply" }) do |name|
- # link_to(name, { :controller => "accounts", :action => "signup" })
+ # link_to_unless(@current_user.nil?, "Reply", { action: "reply" }) do |name|
+ # link_to(name, { controller: "accounts", action: "signup" })
# end
# %>
# # If the user is logged in...
@@ -396,13 +394,13 @@ module ActionView
# in +link_to_unless+).
#
# ==== Examples
- # <%= link_to_if(@current_user.nil?, "Login", { :controller => "sessions", :action => "new" }) %>
+ # <%= link_to_if(@current_user.nil?, "Login", { controller: "sessions", action: "new" }) %>
# # If the user isn't logged in...
# # => <a href="/sessions/new/">Login</a>
#
# <%=
- # link_to_if(@current_user.nil?, "Login", { :controller => "sessions", :action => "new" }) do
- # link_to(@current_user.login, { :controller => "accounts", :action => "show", :id => @current_user })
+ # link_to_if(@current_user.nil?, "Login", { controller: "sessions", action: "new" }) do
+ # link_to(@current_user.login, { controller: "accounts", action: "show", id: @current_user })
# end
# %>
# # If the user isn't logged in...
@@ -443,17 +441,17 @@ module ActionView
# mail_to "me@domain.com"
# # => <a href="mailto:me@domain.com">me@domain.com</a>
#
- # mail_to "me@domain.com", "My email", :encode => "javascript"
+ # mail_to "me@domain.com", "My email", encode: "javascript"
# # => <script>eval(decodeURIComponent('%64%6f%63...%27%29%3b'))</script>
#
- # mail_to "me@domain.com", "My email", :encode => "hex"
+ # mail_to "me@domain.com", "My email", encode: "hex"
# # => <a href="mailto:%6d%65@%64%6f%6d%61%69%6e.%63%6f%6d">My email</a>
#
- # mail_to "me@domain.com", nil, :replace_at => "_at_", :replace_dot => "_dot_", :class => "email"
+ # mail_to "me@domain.com", nil, replace_at: "_at_", replace_dot: "_dot_", class: "email"
# # => <a href="mailto:me@domain.com" class="email">me_at_domain_dot_com</a>
#
- # mail_to "me@domain.com", "My email", :cc => "ccaddress@domain.com",
- # :subject => "This is an example email"
+ # mail_to "me@domain.com", "My email", cc: "ccaddress@domain.com",
+ # subject: "This is an example email"
# # => <a href="mailto:me@domain.com?cc=ccaddress@domain.com&subject=This%20is%20an%20example%20email">My email</a>
def mail_to(email_address, name = nil, html_options = {})
email_address = ERB::Util.html_escape(email_address)
@@ -502,47 +500,47 @@ module ActionView
# ==== Examples
# Let's say we're in the <tt>/shop/checkout?order=desc</tt> action.
#
- # current_page?(:action => 'process')
+ # current_page?(action: 'process')
# # => false
#
- # current_page?(:controller => 'shop', :action => 'checkout')
+ # current_page?(controller: 'shop', action: 'checkout')
# # => true
#
- # current_page?(:controller => 'shop', :action => 'checkout', :order => 'asc')
+ # current_page?(controller: 'shop', action: 'checkout', order: 'asc')
# # => false
#
- # current_page?(:action => 'checkout')
+ # current_page?(action: 'checkout')
# # => true
#
- # current_page?(:controller => 'library', :action => 'checkout')
+ # current_page?(controller: 'library', action: 'checkout')
# # => false
#
# Let's say we're in the <tt>/shop/checkout?order=desc&page=1</tt> action.
#
- # current_page?(:action => 'process')
+ # current_page?(action: 'process')
# # => false
#
- # current_page?(:controller => 'shop', :action => 'checkout')
+ # current_page?(controller: 'shop', action: 'checkout')
# # => true
#
- # current_page?(:controller => 'shop', :action => 'checkout', :order => 'desc', :page => '1')
+ # current_page?(controller: 'shop', action: 'checkout', order: 'desc', page: '1')
# # => true
#
- # current_page?(:controller => 'shop', :action => 'checkout', :order => 'desc', :page => '2')
+ # current_page?(controller: 'shop', action: 'checkout', order: 'desc', page: '2')
# # => false
#
- # current_page?(:controller => 'shop', :action => 'checkout', :order => 'desc')
+ # current_page?(controller: 'shop', action: 'checkout', order: 'desc')
# # => false
#
- # current_page?(:action => 'checkout')
+ # current_page?(action: 'checkout')
# # => true
#
- # current_page?(:controller => 'library', :action => 'checkout')
+ # current_page?(controller: 'library', action: 'checkout')
# # => false
#
# Let's say we're in the <tt>/products</tt> action with method POST in case of invalid product.
#
- # current_page?(:controller => 'product', :action => 'index')
+ # current_page?(controller: 'product', action: 'index')
# # => false
#
def current_page?(options)
@@ -642,14 +640,14 @@ module ActionView
def token_tag(token=nil)
if token != false && protect_against_forgery?
token ||= form_authenticity_token
- tag(:input, :type => "hidden", :name => request_forgery_protection_token.to_s, :value => token)
+ tag(:input, type: "hidden", name: request_forgery_protection_token.to_s, value: token)
else
''
end
end
def method_tag(method)
- tag('input', :type => 'hidden', :name => '_method', :value => method.to_s)
+ tag('input', type: 'hidden', name: '_method', value: method.to_s)
end
end
end