Skip to content
Newer
Older
100644 637 lines (595 sloc) 28.7 KB
0eacdcf @jeremy Use a consistent load path to avoid double requires. Fix some scatter…
jeremy authored Jan 28, 2007
1 require 'action_view/helpers/javascript_helper'
67eb892 @josh AV::UrlHelper depends on Array#second
josh authored Sep 13, 2009
2 require 'active_support/core_ext/array/access'
23f3b56 @jeremy Uses Hash#symbolize_keys
jeremy authored Jun 8, 2009
3 require 'active_support/core_ext/hash/keys'
8910de6 @jamis Make link_to escape the javascript in the confirm option #1964 [nicol…
jamis authored Aug 14, 2005
4
db045db @dhh Initial
dhh authored Nov 24, 2004
5 module ActionView
986c1a6 @dhh Deprecated UrlHelper#link_to_image and UrlHelper#link_to :post => tru…
dhh authored Oct 22, 2006
6 module Helpers #:nodoc:
f07d0e2 Enhance documentation and add examples for url_for. Closes #8227. [je…
Marcel Molina authored May 6, 2007
7 # Provides a set of methods for making links and getting URLs that
c98692a @clemens Removed handling of string parameter in link_to to have all URL gener…
clemens authored Jul 19, 2008
8 # depend on the routing subsystem (see ActionController::Routing).
9 # This allows you to use the same format for links in views
f07d0e2 Enhance documentation and add examples for url_for. Closes #8227. [je…
Marcel Molina authored May 6, 2007
10 # and controllers.
db045db @dhh Initial
dhh authored Nov 24, 2004
11 module UrlHelper
8910de6 @jamis Make link_to escape the javascript in the confirm option #1964 [nicol…
jamis authored Aug 14, 2005
12 include JavaScriptHelper
dfc1285 @jeremy Deprecation: remove deprecated link_to_image and link_image_to method…
jeremy authored Mar 13, 2007
13
f149eb1 @josevalim From now on, parameters defined in default_url_options can be absent …
josevalim authored Jan 7, 2010
14 # Need to map default url options to controller one.
15 def default_url_options(*args) #:nodoc:
1a750da @josh Make @controller an internal ivar in the view
josh authored Jan 22, 2010
16 controller.send(:default_url_options, *args)
f149eb1 @josevalim From now on, parameters defined in default_url_options can be absent …
josevalim authored Jan 7, 2010
17 end
18
dfc1285 @jeremy Deprecation: remove deprecated link_to_image and link_image_to method…
jeremy authored Mar 13, 2007
19 # Returns the URL for the set of +options+ provided. This takes the
98dc582 @lifo Merge docrails.
lifo authored May 25, 2008
20 # same options as +url_for+ in Action Controller (see the
e033b5d @lifo Merge docrails
lifo authored Jul 25, 2009
21 # documentation for <tt>ActionController::Base#url_for</tt>). Note that by default
22 # <tt>:only_path</tt> is <tt>true</tt> so you'll get the relative "/controller/action"
23 # instead of the fully qualified URL like "http://example.com/controller/action".
dfc1285 @jeremy Deprecation: remove deprecated link_to_image and link_image_to method…
jeremy authored Mar 13, 2007
24 #
e033b5d @lifo Merge docrails
lifo authored Jul 25, 2009
25 # When called from a view, +url_for+ returns an HTML escaped url. If you
64092de @fxn Improve documentation coverage and markup
fxn authored May 2, 2008
26 # need an unescaped url, pass <tt>:escape => false</tt> in the +options+.
f07d0e2 Enhance documentation and add examples for url_for. Closes #8227. [je…
Marcel Molina authored May 6, 2007
27 #
28 # ==== Options
dc4eec1 @lifo Merge docrails:
lifo authored May 9, 2008
29 # * <tt>:anchor</tt> - Specifies the anchor name to be appended to the path.
30 # * <tt>:only_path</tt> - If true, returns the relative URL (omitting the protocol, host name, and port) (<tt>true</tt> by default unless <tt>:host</tt> is specified).
31 # * <tt>:trailing_slash</tt> - If true, adds a trailing slash, as in "/archive/2005/". Note that this
f07d0e2 Enhance documentation and add examples for url_for. Closes #8227. [je…
Marcel Molina authored May 6, 2007
32 # is currently not recommended since it breaks caching.
dc4eec1 @lifo Merge docrails:
lifo authored May 9, 2008
33 # * <tt>:host</tt> - Overrides the default (current) host if provided.
34 # * <tt>:protocol</tt> - Overrides the default (current) protocol if provided.
35 # * <tt>:user</tt> - Inline HTTP authentication (only plucked out if <tt>:password</tt> is also present).
36 # * <tt>:password</tt> - Inline HTTP authentication (only plucked out if <tt>:user</tt> is also present).
37 # * <tt>:escape</tt> - Determines whether the returned URL will be HTML escaped or not (<tt>true</tt> by default).
f07d0e2 Enhance documentation and add examples for url_for. Closes #8227. [je…
Marcel Molina authored May 6, 2007
38 #
c769ad8 @dhh Removed deprecated parameters_for_method_reference concept (legacy fr…
dhh authored May 12, 2007
39 # ==== Relying on named routes
40 #
41 # If you instead of a hash pass a record (like an Active Record or Active Resource) as the options parameter,
42 # you'll trigger the named route for that record. The lookup will happen on the name of the class. So passing
e033b5d @lifo Merge docrails
lifo authored Jul 25, 2009
43 # a Workshop object will attempt to use the +workshop_path+ route. If you have a nested route, such as
44 # +admin_workshop_path+ you'll have to call that explicitly (it's impossible for +url_for+ to guess that route).
c769ad8 @dhh Removed deprecated parameters_for_method_reference concept (legacy fr…
dhh authored May 12, 2007
45 #
f07d0e2 Enhance documentation and add examples for url_for. Closes #8227. [je…
Marcel Molina authored May 6, 2007
46 # ==== Examples
47 # <%= url_for(:action => 'index') %>
48 # # => /blog/
49 #
50 # <%= url_for(:action => 'find', :controller => 'books') %>
51 # # => /books/find
52 #
53 # <%= url_for(:action => 'login', :controller => 'members', :only_path => false, :protocol => 'https') %>
54 # # => https://www.railsapplication.com/members/login/
55 #
56 # <%= url_for(:action => 'play', :anchor => 'player') %>
57 # # => /messages/play/#player
58 #
59 # <%= url_for(:action => 'checkout', :anchor => 'tax&ship') %>
60 # # => /testing/jump/#tax&amp;ship
61 #
62 # <%= url_for(:action => 'checkout', :anchor => 'tax&ship', :escape => false) %>
63 # # => /testing/jump/#tax&ship
c769ad8 @dhh Removed deprecated parameters_for_method_reference concept (legacy fr…
dhh authored May 12, 2007
64 #
65 # <%= url_for(Workshop.new) %>
66 # # relies on Workshop answering a new_record? call (and in this case returning true)
67 # # => /workshops
68 #
69 # <%= url_for(@workshop) %>
70 # # calls @workshop.to_s
71 # # => /workshops/5
c98692a @clemens Removed handling of string parameter in link_to to have all URL gener…
clemens authored Jul 19, 2008
72 #
73 # <%= url_for("http://www.example.com") %>
74 # # => http://www.example.com
75 #
76 # <%= url_for(:back) %>
77 # # if request.env["HTTP_REFERER"] is set to "http://www.example.com"
78 # # => http://www.example.com
79 #
80 # <%= url_for(:back) %>
81 # # if request.env["HTTP_REFERER"] is not set or is blank
82 # # => javascript:history.back()
c769ad8 @dhh Removed deprecated parameters_for_method_reference concept (legacy fr…
dhh authored May 12, 2007
83 def url_for(options = {})
96708af @chuyeow Ensure url_for(nil) falls back to url_for({}). [#472 state:resolved]
chuyeow authored Jun 23, 2008
84 options ||= {}
c98692a @clemens Removed handling of string parameter in link_to to have all URL gener…
clemens authored Jul 19, 2008
85 url = case options
86 when String
87 escape = true
88 options
c769ad8 @dhh Removed deprecated parameters_for_method_reference concept (legacy fr…
dhh authored May 12, 2007
89 when Hash
96708af @chuyeow Ensure url_for(nil) falls back to url_for({}). [#472 state:resolved]
chuyeow authored Jun 23, 2008
90 options = { :only_path => options[:host].nil? }.update(options.symbolize_keys)
1b3195b ActionView.url_for doesn't escape by default
Phil Darnowsky authored Oct 7, 2009
91 escape = options.key?(:escape) ? options.delete(:escape) : false
1a750da @josh Make @controller an internal ivar in the view
josh authored Jan 22, 2010
92 controller.send(:url_for, options)
c98692a @clemens Removed handling of string parameter in link_to to have all URL gener…
clemens authored Jul 19, 2008
93 when :back
94 escape = false
1a750da @josh Make @controller an internal ivar in the view
josh authored Jan 22, 2010
95 controller.request.env["HTTP_REFERER"] || 'javascript:history.back()'
c769ad8 @dhh Removed deprecated parameters_for_method_reference concept (legacy fr…
dhh authored May 12, 2007
96 else
97 escape = false
c98692a @clemens Removed handling of string parameter in link_to to have all URL gener…
clemens authored Jul 19, 2008
98 polymorphic_path(options)
c05c22a @seckar Fix double url escaping of remote_function. Add :escape => false opti…
seckar authored Mar 22, 2006
99 end
140a998 @dhh Added :method handling for other verbs to remote_form_tag and remote_…
dhh authored May 28, 2006
100
1d01bad @NZKoz Make sure non-escaped urls aren't considered safe
NZKoz authored Oct 15, 2009
101 escape ? escape_once(url).html_safe! : url
db045db @dhh Initial
dhh authored Nov 24, 2004
102 end
103
dfc1285 @jeremy Deprecation: remove deprecated link_to_image and link_image_to method…
jeremy authored Mar 13, 2007
104 # Creates a link tag of the given +name+ using a URL created by the set
105 # of +options+. See the valid options in the documentation for
e033b5d @lifo Merge docrails
lifo authored Jul 25, 2009
106 # +url_for+. It's also possible to pass a string instead
dfc1285 @jeremy Deprecation: remove deprecated link_to_image and link_image_to method…
jeremy authored Mar 13, 2007
107 # of an options hash to get a link tag that uses the value of the string as the
aa4af60 @lifo Improve documentation.
lifo authored Apr 5, 2008
108 # href for the link, or use <tt>:back</tt> to link to the referrer - a JavaScript back
e033b5d @lifo Merge docrails
lifo authored Jul 25, 2009
109 # link will be used in place of a referrer if none exists. If +nil+ is passed as
074fe35 @NZKoz Add link_to :back which uses your referrer with a fallback to a javas…
NZKoz authored Oct 8, 2007
110 # a name, the link itself will become the name.
258bacb @dhh Added :popup option to UrlHelper#link_to #1996 [gabriel.gironda@gmail…
dhh authored Sep 4, 2005
111 #
8190bce @dhh Added block-call style to link_to [Sam Stephenson/DHH]
dhh authored Jun 17, 2008
112 # ==== Signatures
113 #
114 # link_to(name, options = {}, html_options = nil)
115 # link_to(options = {}, html_options = nil) do
116 # # name
117 # end
118 #
f07d0e2 Enhance documentation and add examples for url_for. Closes #8227. [je…
Marcel Molina authored May 6, 2007
119 # ==== Options
dc4eec1 @lifo Merge docrails:
lifo authored May 9, 2008
120 # * <tt>:confirm => 'question?'</tt> - This will add a JavaScript confirm
dfc1285 @jeremy Deprecation: remove deprecated link_to_image and link_image_to method…
jeremy authored Mar 13, 2007
121 # prompt with the question specified. If the user accepts, the link is
986c1a6 @dhh Deprecated UrlHelper#link_to_image and UrlHelper#link_to :post => tru…
dhh authored Oct 22, 2006
122 # processed normally, otherwise no action is taken.
dc4eec1 @lifo Merge docrails:
lifo authored May 9, 2008
123 # * <tt>:method => symbol of HTTP verb</tt> - This modifier will dynamically
dfc1285 @jeremy Deprecation: remove deprecated link_to_image and link_image_to method…
jeremy authored Mar 13, 2007
124 # create an HTML form and immediately submit the form for processing using
986c1a6 @dhh Deprecated UrlHelper#link_to_image and UrlHelper#link_to :post => tru…
dhh authored Oct 22, 2006
125 # the HTTP verb specified. Useful for having links perform a POST operation
126 # in dangerous actions like deleting a record (which search bots can follow
64092de @fxn Improve documentation coverage and markup
fxn authored May 2, 2008
127 # while spidering your site). Supported verbs are <tt>:post</tt>, <tt>:delete</tt> and <tt>:put</tt>.
dfc1285 @jeremy Deprecation: remove deprecated link_to_image and link_image_to method…
jeremy authored Mar 13, 2007
128 # Note that if the user has JavaScript disabled, the request will fall back
e033b5d @lifo Merge docrails
lifo authored Jul 25, 2009
129 # to using GET. If <tt>:href => '#'</tt> is used and the user has JavaScript
130 # disabled clicking the link will have no effect. If you are relying on the
131 # POST behavior, you should check for it in your controller's action by using
132 # the request object's methods for <tt>post?</tt>, <tt>delete?</tt> or <tt>put?</tt>.
f07d0e2 Enhance documentation and add examples for url_for. Closes #8227. [je…
Marcel Molina authored May 6, 2007
133 # * The +html_options+ will accept a hash of html attributes for the link tag.
258bacb @dhh Added :popup option to UrlHelper#link_to #1996 [gabriel.gironda@gmail…
dhh authored Sep 4, 2005
134 #
f07d0e2 Enhance documentation and add examples for url_for. Closes #8227. [je…
Marcel Molina authored May 6, 2007
135 # ==== Examples
46f30f9 @lifo Merge documentation changes from docrails.
lifo authored May 16, 2008
136 # Because it relies on +url_for+, +link_to+ supports both older-style controller/action/id arguments
137 # and newer RESTful routes. Current Rails style favors RESTful routes whenever possible, so base
138 # your application on resources and use
139 #
140 # link_to "Profile", profile_path(@profile)
141 # # => <a href="/profiles/1">Profile</a>
142 #
143 # or the even pithier
144 #
145 # link_to "Profile", @profile
146 # # => <a href="/profiles/1">Profile</a>
147 #
148 # in place of the older more verbose, non-resource-oriented
149 #
150 # link_to "Profile", :controller => "profiles", :action => "show", :id => @profile
151 # # => <a href="/profiles/show/1">Profile</a>
c98692a @clemens Removed handling of string parameter in link_to to have all URL gener…
clemens authored Jul 19, 2008
152 #
153 # Similarly,
46f30f9 @lifo Merge documentation changes from docrails.
lifo authored May 16, 2008
154 #
155 # link_to "Profiles", profiles_path
156 # # => <a href="/profiles">Profiles</a>
157 #
158 # is better than
159 #
160 # link_to "Profiles", :controller => "profiles"
161 # # => <a href="/profiles">Profiles</a>
162 #
8190bce @dhh Added block-call style to link_to [Sam Stephenson/DHH]
dhh authored Jun 17, 2008
163 # You can use a block as well if your link target is hard to fit into the name parameter. ERb example:
164 #
165 # <% link_to(@profile) do %>
e033b5d @lifo Merge docrails
lifo authored Jul 25, 2009
166 # <strong><%= @profile.name %></strong> -- <span>Check it out!</span>
8190bce @dhh Added block-call style to link_to [Sam Stephenson/DHH]
dhh authored Jun 17, 2008
167 # <% end %>
e033b5d @lifo Merge docrails
lifo authored Jul 25, 2009
168 # # => <a href="/profiles/1">
169 # <strong>David</strong> -- <span>Check it out!</span>
170 # </a>
8190bce @dhh Added block-call style to link_to [Sam Stephenson/DHH]
dhh authored Jun 17, 2008
171 #
46f30f9 @lifo Merge documentation changes from docrails.
lifo authored May 16, 2008
172 # Classes and ids for CSS are easy to produce:
173 #
174 # link_to "Articles", articles_path, :id => "news", :class => "article"
175 # # => <a href="/articles" class="article" id="news">Articles</a>
176 #
177 # Be careful when using the older argument style, as an extra literal hash is needed:
178 #
179 # link_to "Articles", { :controller => "articles" }, :id => "news", :class => "article"
180 # # => <a href="/articles" class="article" id="news">Articles</a>
181 #
182 # Leaving the hash off gives the wrong link:
183 #
184 # link_to "WRONG!", :controller => "articles", :id => "news", :class => "article"
185 # # => <a href="/articles/index/news?class=article">WRONG!</a>
186 #
187 # +link_to+ can also produce links with anchors or query strings:
188 #
189 # link_to "Comment wall", profile_path(@profile, :anchor => "wall")
190 # # => <a href="/profiles/1#wall">Comment wall</a>
191 #
192 # link_to "Ruby on Rails search", :controller => "searches", :query => "ruby on rails"
193 # # => <a href="/searches?query=ruby+on+rails">Ruby on Rails search</a>
194 #
195 # link_to "Nonsense search", searches_path(:foo => "bar", :baz => "quux")
196 # # => <a href="/searches?foo=bar&amp;baz=quux">Nonsense search</a>
197 #
bddd1bb @josh Deprecate link_to :popup
josh authored Jan 29, 2010
198 # The three options specific to +link_to+ (<tt>:confirm</tt> and <tt>:method</tt>) are used as follows:
46f30f9 @lifo Merge documentation changes from docrails.
lifo authored May 16, 2008
199 #
986c1a6 @dhh Deprecated UrlHelper#link_to_image and UrlHelper#link_to :post => tru…
dhh authored Oct 22, 2006
200 # link_to "Visit Other Site", "http://www.rubyonrails.org/", :confirm => "Are you sure?"
f07d0e2 Enhance documentation and add examples for url_for. Closes #8227. [je…
Marcel Molina authored May 6, 2007
201 # # => <a href="http://www.rubyonrails.org/" onclick="return confirm('Are you sure?');">Visit Other Site</a>
202 #
46f30f9 @lifo Merge documentation changes from docrails.
lifo authored May 16, 2008
203 # link_to "Delete Image", @image, :confirm => "Are you sure?", :method => :delete
c98692a @clemens Removed handling of string parameter in link_to to have all URL gener…
clemens authored Jul 19, 2008
204 # # => <a href="/images/9" onclick="if (confirm('Are you sure?')) { var f = document.createElement('form');
f07d0e2 Enhance documentation and add examples for url_for. Closes #8227. [je…
Marcel Molina authored May 6, 2007
205 # f.style.display = 'none'; this.parentNode.appendChild(f); f.method = 'POST'; f.action = this.href;
c98692a @clemens Removed handling of string parameter in link_to to have all URL gener…
clemens authored Jul 19, 2008
206 # var m = document.createElement('input'); m.setAttribute('type', 'hidden'); m.setAttribute('name', '_method');
e033b5d @lifo Merge docrails
lifo authored Jul 25, 2009
207 # m.setAttribute('value', 'delete');var s = document.createElement('input'); s.setAttribute('type', 'hidden');
208 # s.setAttribute('name', 'authenticity_token'); s.setAttribute('value', 'Q/ttlxPYZ6R77B+vZ1sBkhj21G2isO9dpE6UtOHBApg=');
209 # f.appendChild(s)f.appendChild(m);f.submit(); };return false;">Delete Image</a>
8190bce @dhh Added block-call style to link_to [Sam Stephenson/DHH]
dhh authored Jun 17, 2008
210 def link_to(*args, &block)
211 if block_given?
212 options = args.first || {}
213 html_options = args.second
9415935 @NZKoz Switch to on-by-default XSS escaping for rails.
NZKoz authored Oct 8, 2009
214 concat(link_to(capture(&block), options, html_options).html_safe!)
8190bce @dhh Added block-call style to link_to [Sam Stephenson/DHH]
dhh authored Jun 17, 2008
215 else
86fc43f ActionPack components should no longer have undeclared dependencies.
Yehuda Katz + Carl Lerche authored Jun 8, 2009
216 name = args[0]
217 options = args[1] || {}
218 html_options = args[2]
8190bce @dhh Added block-call style to link_to [Sam Stephenson/DHH]
dhh authored Jun 17, 2008
219
c98692a @clemens Removed handling of string parameter in link_to to have all URL gener…
clemens authored Jul 19, 2008
220 url = url_for(options)
392817c @erikstmartin updating link_to and button_to to support :remote => true and other o…
erikstmartin authored Jan 30, 2010
221 html_options = convert_options_to_data_attributes(options, html_options)
8190bce @dhh Added block-call style to link_to [Sam Stephenson/DHH]
dhh authored Jun 17, 2008
222
223 if html_options
224 html_options = html_options.stringify_keys
225 href = html_options['href']
226 tag_options = tag_options(html_options)
074fe35 @NZKoz Add link_to :back which uses your referrer with a fallback to a javas…
NZKoz authored Oct 8, 2007
227 else
8190bce @dhh Added block-call style to link_to [Sam Stephenson/DHH]
dhh authored Jun 17, 2008
228 tag_options = nil
074fe35 @NZKoz Add link_to :back which uses your referrer with a fallback to a javas…
NZKoz authored Oct 8, 2007
229 end
c98692a @clemens Removed handling of string parameter in link_to to have all URL gener…
clemens authored Jul 19, 2008
230
8190bce @dhh Added block-call style to link_to [Sam Stephenson/DHH]
dhh authored Jun 17, 2008
231 href_attr = "href=\"#{url}\"" unless href
9415935 @NZKoz Switch to on-by-default XSS escaping for rails.
NZKoz authored Oct 7, 2009
232 "<a #{href_attr}#{tag_options}>#{ERB::Util.h(name || url)}</a>".html_safe!
db045db @dhh Initial
dhh authored Nov 24, 2004
233 end
234 end
235
986c1a6 @dhh Deprecated UrlHelper#link_to_image and UrlHelper#link_to :post => tru…
dhh authored Oct 22, 2006
236 # Generates a form containing a single button that submits to the URL created
237 # by the set of +options+. This is the safest method to ensure links that
238 # cause changes to your data are not triggered by search bots or accelerators.
239 # If the HTML button does not work with your layout, you can also consider
e033b5d @lifo Merge docrails
lifo authored Jul 25, 2009
240 # using the +link_to+ method with the <tt>:method</tt> modifier as described in
241 # the +link_to+ documentation.
43c470f @dhh Added button_to as a form-based solution to deal with harmful actions…
dhh authored Jun 16, 2005
242 #
e033b5d @lifo Merge docrails
lifo authored Jul 25, 2009
243 # The generated form element has a class name of <tt>button-to</tt>
986c1a6 @dhh Deprecated UrlHelper#link_to_image and UrlHelper#link_to :post => tru…
dhh authored Oct 22, 2006
244 # to allow styling of the form itself and its children. You can control
245 # the form submission and input element behavior using +html_options+.
246 # This method accepts the <tt>:method</tt> and <tt>:confirm</tt> modifiers
e033b5d @lifo Merge docrails
lifo authored Jul 25, 2009
247 # described in the +link_to+ documentation. If no <tt>:method</tt> modifier
dfc1285 @jeremy Deprecation: remove deprecated link_to_image and link_image_to method…
jeremy authored Mar 13, 2007
248 # is given, it will default to performing a POST operation. You can also
986c1a6 @dhh Deprecated UrlHelper#link_to_image and UrlHelper#link_to :post => tru…
dhh authored Oct 22, 2006
249 # disable the button by passing <tt>:disabled => true</tt> in +html_options+.
250 # If you are using RESTful routes, you can pass the <tt>:method</tt>
251 # to change the HTTP verb used to submit the form.
43c470f @dhh Added button_to as a form-based solution to deal with harmful actions…
dhh authored Jun 16, 2005
252 #
f07d0e2 Enhance documentation and add examples for url_for. Closes #8227. [je…
Marcel Molina authored May 6, 2007
253 # ==== Options
e033b5d @lifo Merge docrails
lifo authored Jul 25, 2009
254 # The +options+ hash accepts the same options as url_for.
43c470f @dhh Added button_to as a form-based solution to deal with harmful actions…
dhh authored Jun 16, 2005
255 #
f07d0e2 Enhance documentation and add examples for url_for. Closes #8227. [je…
Marcel Molina authored May 6, 2007
256 # There are a few special +html_options+:
dc4eec1 @lifo Merge docrails:
lifo authored May 9, 2008
257 # * <tt>:method</tt> - Specifies the anchor name to be appended to the path.
258 # * <tt>:disabled</tt> - Specifies the anchor name to be appended to the path.
259 # * <tt>:confirm</tt> - This will add a JavaScript confirm
f07d0e2 Enhance documentation and add examples for url_for. Closes #8227. [je…
Marcel Molina authored May 6, 2007
260 # prompt with the question specified. If the user accepts, the link is
261 # processed normally, otherwise no action is taken.
c98692a @clemens Removed handling of string parameter in link_to to have all URL gener…
clemens authored Jul 19, 2008
262 #
f07d0e2 Enhance documentation and add examples for url_for. Closes #8227. [je…
Marcel Molina authored May 6, 2007
263 # ==== Examples
264 # <%= button_to "New", :action => "new" %>
265 # # => "<form method="post" action="/controller/new" class="button-to">
266 # # <div><input value="New" type="submit" /></div>
267 # # </form>"
43c470f @dhh Added button_to as a form-based solution to deal with harmful actions…
dhh authored Jun 16, 2005
268 #
f07d0e2 Enhance documentation and add examples for url_for. Closes #8227. [je…
Marcel Molina authored May 6, 2007
269 # button_to "Delete Image", { :action => "delete", :id => @image.id },
270 # :confirm => "Are you sure?", :method => :delete
271 # # => "<form method="post" action="/images/delete/1" class="button-to">
272 # # <div>
273 # # <input type="hidden" name="_method" value="delete" />
274 # # <input onclick="return confirm('Are you sure?');"
275 # # value="Delete" type="submit" />
276 # # </div>
277 # # </form>"
986c1a6 @dhh Deprecated UrlHelper#link_to_image and UrlHelper#link_to :post => tru…
dhh authored Oct 22, 2006
278 def button_to(name, options = {}, html_options = {})
279 html_options = html_options.stringify_keys
43c470f @dhh Added button_to as a form-based solution to deal with harmful actions…
dhh authored Jun 16, 2005
280 convert_boolean_attributes!(html_options, %w( disabled ))
a769b88 @jeremy button_to accepts :method so you can PUT and DELETE with it. Closes #…
jeremy authored Sep 3, 2006
281
282 method_tag = ''
283 if (method = html_options.delete('method')) && %w{put delete}.include?(method.to_s)
284 method_tag = tag('input', :type => 'hidden', :name => '_method', :value => method.to_s)
285 end
286
287 form_method = method.to_s == 'get' ? 'get' : 'post'
c98692a @clemens Removed handling of string parameter in link_to to have all URL gener…
clemens authored Jul 19, 2008
288
82c1fed @dhh Protect button_to behind protect_from_forgery (closes #9675) [lifo]
dhh authored Sep 25, 2007
289 request_token_tag = ''
5edc81d @technoweenie Allow ability to disable request forgery protection, disable it in te…
technoweenie authored Sep 28, 2007
290 if form_method == 'post' && protect_against_forgery?
82c1fed @dhh Protect button_to behind protect_from_forgery (closes #9675) [lifo]
dhh authored Sep 25, 2007
291 request_token_tag = tag(:input, :type => "hidden", :name => request_forgery_protection_token.to_s, :value => form_authenticity_token)
292 end
c98692a @clemens Removed handling of string parameter in link_to to have all URL gener…
clemens authored Jul 19, 2008
293
986c1a6 @dhh Deprecated UrlHelper#link_to_image and UrlHelper#link_to :post => tru…
dhh authored Oct 22, 2006
294 url = options.is_a?(String) ? options : self.url_for(options)
1e7ce13 @seckar Change url_for to escape the resulting URLs when called from a view. …
seckar authored Mar 18, 2006
295 name ||= url
bddd1bb @josh Deprecate link_to :popup
josh authored Jan 30, 2010
296
392817c @erikstmartin updating link_to and button_to to support :remote => true and other o…
erikstmartin authored Jan 31, 2010
297 html_options = convert_options_to_data_attributes(options, html_options)
a769b88 @jeremy button_to accepts :method so you can PUT and DELETE with it. Closes #…
jeremy authored Sep 3, 2006
298
43c470f @dhh Added button_to as a form-based solution to deal with harmful actions…
dhh authored Jun 16, 2005
299 html_options.merge!("type" => "submit", "value" => name)
e1917ca @dhh Added link_to_image(src, options = {}, html_options = {}, *parameters…
dhh authored Dec 9, 2004
300
9415935 @NZKoz Switch to on-by-default XSS escaping for rails.
NZKoz authored Oct 7, 2009
301 ("<form method=\"#{form_method}\" action=\"#{escape_once url}\" class=\"button-to\"><div>" +
302 method_tag + tag("input", html_options) + request_token_tag + "</div></form>").html_safe!
e1917ca @dhh Added link_to_image(src, options = {}, html_options = {}, *parameters…
dhh authored Dec 9, 2004
303 end
304
9bb8c10 @dhh Renamed link_to_image to link_image_to (since thats what it actually …
dhh authored Feb 19, 2005
305
986c1a6 @dhh Deprecated UrlHelper#link_to_image and UrlHelper#link_to :post => tru…
dhh authored Oct 22, 2006
306 # Creates a link tag of the given +name+ using a URL created by the set of
f07d0e2 Enhance documentation and add examples for url_for. Closes #8227. [je…
Marcel Molina authored May 6, 2007
307 # +options+ unless the current request URI is the same as the links, in
986c1a6 @dhh Deprecated UrlHelper#link_to_image and UrlHelper#link_to :post => tru…
dhh authored Oct 22, 2006
308 # which case only the name is returned (or the given block is yielded, if
e033b5d @lifo Merge docrails
lifo authored Jul 25, 2009
309 # one exists). You can give +link_to_unless_current+ a block which will
f07d0e2 Enhance documentation and add examples for url_for. Closes #8227. [je…
Marcel Molina authored May 6, 2007
310 # specialize the default behavior (e.g., show a "Start Here" link rather
311 # than the link's text).
312 #
313 # ==== Examples
314 # Let's say you have a navigation menu...
986c1a6 @dhh Deprecated UrlHelper#link_to_image and UrlHelper#link_to :post => tru…
dhh authored Oct 22, 2006
315 #
316 # <ul id="navbar">
317 # <li><%= link_to_unless_current("Home", { :action => "index" }) %></li>
318 # <li><%= link_to_unless_current("About Us", { :action => "about" }) %></li>
319 # </ul>
320 #
f07d0e2 Enhance documentation and add examples for url_for. Closes #8227. [je…
Marcel Molina authored May 6, 2007
321 # If in the "about" action, it will render...
986c1a6 @dhh Deprecated UrlHelper#link_to_image and UrlHelper#link_to :post => tru…
dhh authored Oct 22, 2006
322 #
323 # <ul id="navbar">
324 # <li><a href="/controller/index">Home</a></li>
325 # <li>About Us</li>
326 # </ul>
f07d0e2 Enhance documentation and add examples for url_for. Closes #8227. [je…
Marcel Molina authored May 6, 2007
327 #
3ecde39 @dhh Docfix (closes #11226) [mikong]
dhh authored Mar 15, 2008
328 # ...but if in the "index" action, it will render:
f07d0e2 Enhance documentation and add examples for url_for. Closes #8227. [je…
Marcel Molina authored May 6, 2007
329 #
330 # <ul id="navbar">
3ecde39 @dhh Docfix (closes #11226) [mikong]
dhh authored Mar 15, 2008
331 # <li>Home</li>
f07d0e2 Enhance documentation and add examples for url_for. Closes #8227. [je…
Marcel Molina authored May 6, 2007
332 # <li><a href="/controller/about">About Us</a></li>
333 # </ul>
334 #
e033b5d @lifo Merge docrails
lifo authored Jul 25, 2009
335 # The implicit block given to +link_to_unless_current+ is evaluated if the current
c98692a @clemens Removed handling of string parameter in link_to to have all URL gener…
clemens authored Jul 19, 2008
336 # action is the action given. So, if we had a comments page and wanted to render a
f07d0e2 Enhance documentation and add examples for url_for. Closes #8227. [je…
Marcel Molina authored May 6, 2007
337 # "Go Back" link instead of a link to the comments page, we could do something like this...
c98692a @clemens Removed handling of string parameter in link_to to have all URL gener…
clemens authored Jul 19, 2008
338 #
339 # <%=
f07d0e2 Enhance documentation and add examples for url_for. Closes #8227. [je…
Marcel Molina authored May 6, 2007
340 # link_to_unless_current("Comment", { :controller => 'comments', :action => 'new}) do
c98692a @clemens Removed handling of string parameter in link_to to have all URL gener…
clemens authored Jul 19, 2008
341 # link_to("Go back", { :controller => 'posts', :action => 'index' })
342 # end
f07d0e2 Enhance documentation and add examples for url_for. Closes #8227. [je…
Marcel Molina authored May 6, 2007
343 # %>
c769ad8 @dhh Removed deprecated parameters_for_method_reference concept (legacy fr…
dhh authored May 12, 2007
344 def link_to_unless_current(name, options = {}, html_options = {}, &block)
345 link_to_unless current_page?(options), name, options, html_options, &block
fd9967b @dhh Added UrlHelper#link_to_if/link_to_unless to enable other conditions …
dhh authored Mar 6, 2005
346 end
347
986c1a6 @dhh Deprecated UrlHelper#link_to_image and UrlHelper#link_to :post => tru…
dhh authored Oct 22, 2006
348 # Creates a link tag of the given +name+ using a URL created by the set of
dfc1285 @jeremy Deprecation: remove deprecated link_to_image and link_image_to method…
jeremy authored Mar 13, 2007
349 # +options+ unless +condition+ is true, in which case only the name is
f07d0e2 Enhance documentation and add examples for url_for. Closes #8227. [je…
Marcel Molina authored May 6, 2007
350 # returned. To specialize the default behavior (i.e., show a login link rather
351 # than just the plaintext link text), you can pass a block that
e033b5d @lifo Merge docrails
lifo authored Jul 25, 2009
352 # accepts the name or the full argument list for +link_to_unless+.
986c1a6 @dhh Deprecated UrlHelper#link_to_image and UrlHelper#link_to :post => tru…
dhh authored Oct 22, 2006
353 #
f07d0e2 Enhance documentation and add examples for url_for. Closes #8227. [je…
Marcel Molina authored May 6, 2007
354 # ==== Examples
986c1a6 @dhh Deprecated UrlHelper#link_to_image and UrlHelper#link_to :post => tru…
dhh authored Oct 22, 2006
355 # <%= link_to_unless(@current_user.nil?, "Reply", { :action => "reply" }) %>
f07d0e2 Enhance documentation and add examples for url_for. Closes #8227. [je…
Marcel Molina authored May 6, 2007
356 # # If the user is logged in...
357 # # => <a href="/controller/reply/">Reply</a>
986c1a6 @dhh Deprecated UrlHelper#link_to_image and UrlHelper#link_to :post => tru…
dhh authored Oct 22, 2006
358 #
c98692a @clemens Removed handling of string parameter in link_to to have all URL gener…
clemens authored Jul 19, 2008
359 # <%=
f07d0e2 Enhance documentation and add examples for url_for. Closes #8227. [je…
Marcel Molina authored May 6, 2007
360 # link_to_unless(@current_user.nil?, "Reply", { :action => "reply" }) do |name|
361 # link_to(name, { :controller => "accounts", :action => "signup" })
c98692a @clemens Removed handling of string parameter in link_to to have all URL gener…
clemens authored Jul 19, 2008
362 # end
f07d0e2 Enhance documentation and add examples for url_for. Closes #8227. [je…
Marcel Molina authored May 6, 2007
363 # %>
364 # # If the user is logged in...
365 # # => <a href="/controller/reply/">Reply</a>
366 # # If not...
367 # # => <a href="/accounts/signup">Reply</a>
c769ad8 @dhh Removed deprecated parameters_for_method_reference concept (legacy fr…
dhh authored May 12, 2007
368 def link_to_unless(condition, name, options = {}, html_options = {}, &block)
fd9967b @dhh Added UrlHelper#link_to_if/link_to_unless to enable other conditions …
dhh authored Mar 6, 2005
369 if condition
370 if block_given?
c769ad8 @dhh Removed deprecated parameters_for_method_reference concept (legacy fr…
dhh authored May 12, 2007
371 block.arity <= 1 ? yield(name) : yield(name, options, html_options)
fd9967b @dhh Added UrlHelper#link_to_if/link_to_unless to enable other conditions …
dhh authored Mar 6, 2005
372 else
1d7aa9f @dhh Fixed that UrlHelper#link_to_unless/link_to_if used html_escape on th…
dhh authored Jul 9, 2005
373 name
fd9967b @dhh Added UrlHelper#link_to_if/link_to_unless to enable other conditions …
dhh authored Mar 6, 2005
374 end
db045db @dhh Initial
dhh authored Nov 24, 2004
375 else
c769ad8 @dhh Removed deprecated parameters_for_method_reference concept (legacy fr…
dhh authored May 12, 2007
376 link_to(name, options, html_options)
dfc1285 @jeremy Deprecation: remove deprecated link_to_image and link_image_to method…
jeremy authored Mar 13, 2007
377 end
fd9967b @dhh Added UrlHelper#link_to_if/link_to_unless to enable other conditions …
dhh authored Mar 6, 2005
378 end
dfc1285 @jeremy Deprecation: remove deprecated link_to_image and link_image_to method…
jeremy authored Mar 13, 2007
379
986c1a6 @dhh Deprecated UrlHelper#link_to_image and UrlHelper#link_to :post => tru…
dhh authored Oct 22, 2006
380 # Creates a link tag of the given +name+ using a URL created by the set of
dfc1285 @jeremy Deprecation: remove deprecated link_to_image and link_image_to method…
jeremy authored Mar 13, 2007
381 # +options+ if +condition+ is true, in which case only the name is
986c1a6 @dhh Deprecated UrlHelper#link_to_image and UrlHelper#link_to :post => tru…
dhh authored Oct 22, 2006
382 # returned. To specialize the default behavior, you can pass a block that
e033b5d @lifo Merge docrails
lifo authored Jul 25, 2009
383 # accepts the name or the full argument list for +link_to_unless+ (see the examples
384 # in +link_to_unless+).
f07d0e2 Enhance documentation and add examples for url_for. Closes #8227. [je…
Marcel Molina authored May 6, 2007
385 #
386 # ==== Examples
387 # <%= link_to_if(@current_user.nil?, "Login", { :controller => "sessions", :action => "new" }) %>
388 # # If the user isn't logged in...
389 # # => <a href="/sessions/new/">Login</a>
390 #
c98692a @clemens Removed handling of string parameter in link_to to have all URL gener…
clemens authored Jul 19, 2008
391 # <%=
f07d0e2 Enhance documentation and add examples for url_for. Closes #8227. [je…
Marcel Molina authored May 6, 2007
392 # link_to_if(@current_user.nil?, "Login", { :controller => "sessions", :action => "new" }) do
393 # link_to(@current_user.login, { :controller => "accounts", :action => "show", :id => @current_user })
c98692a @clemens Removed handling of string parameter in link_to to have all URL gener…
clemens authored Jul 19, 2008
394 # end
f07d0e2 Enhance documentation and add examples for url_for. Closes #8227. [je…
Marcel Molina authored May 6, 2007
395 # %>
396 # # If the user isn't logged in...
397 # # => <a href="/sessions/new/">Login</a>
398 # # If they are logged in...
399 # # => <a href="/accounts/show/3">my_username</a>
c769ad8 @dhh Removed deprecated parameters_for_method_reference concept (legacy fr…
dhh authored May 12, 2007
400 def link_to_if(condition, name, options = {}, html_options = {}, &block)
401 link_to_unless !condition, name, options, html_options, &block
db045db @dhh Initial
dhh authored Nov 24, 2004
402 end
403
986c1a6 @dhh Deprecated UrlHelper#link_to_image and UrlHelper#link_to :post => tru…
dhh authored Oct 22, 2006
404 # Creates a mailto link tag to the specified +email_address+, which is
405 # also used as the name of the link unless +name+ is specified. Additional
f07d0e2 Enhance documentation and add examples for url_for. Closes #8227. [je…
Marcel Molina authored May 6, 2007
406 # HTML attributes for the link can be passed in +html_options+.
986c1a6 @dhh Deprecated UrlHelper#link_to_image and UrlHelper#link_to :post => tru…
dhh authored Oct 22, 2006
407 #
e033b5d @lifo Merge docrails
lifo authored Jul 25, 2009
408 # +mail_to+ has several methods for hindering email harvesters and customizing
986c1a6 @dhh Deprecated UrlHelper#link_to_image and UrlHelper#link_to :post => tru…
dhh authored Oct 22, 2006
409 # the email itself by passing special keys to +html_options+.
410 #
f07d0e2 Enhance documentation and add examples for url_for. Closes #8227. [je…
Marcel Molina authored May 6, 2007
411 # ==== Options
e033b5d @lifo Merge docrails
lifo authored Jul 25, 2009
412 # * <tt>:encode</tt> - This key will accept the strings "javascript" or "hex".
413 # Passing "javascript" will dynamically create and encode the mailto link then
986c1a6 @dhh Deprecated UrlHelper#link_to_image and UrlHelper#link_to :post => tru…
dhh authored Oct 22, 2006
414 # eval it into the DOM of the page. This method will not show the link on
415 # the page if the user has JavaScript disabled. Passing "hex" will hex
e033b5d @lifo Merge docrails
lifo authored Jul 25, 2009
416 # encode the +email_address+ before outputting the mailto link.
417 # * <tt>:replace_at</tt> - When the link +name+ isn't provided, the
986c1a6 @dhh Deprecated UrlHelper#link_to_image and UrlHelper#link_to :post => tru…
dhh authored Oct 22, 2006
418 # +email_address+ is used for the link label. You can use this option to
419 # obfuscate the +email_address+ by substituting the @ sign with the string
420 # given as the value.
e033b5d @lifo Merge docrails
lifo authored Jul 25, 2009
421 # * <tt>:replace_dot</tt> - When the link +name+ isn't provided, the
986c1a6 @dhh Deprecated UrlHelper#link_to_image and UrlHelper#link_to :post => tru…
dhh authored Oct 22, 2006
422 # +email_address+ is used for the link label. You can use this option to
423 # obfuscate the +email_address+ by substituting the . in the email with the
424 # string given as the value.
e033b5d @lifo Merge docrails
lifo authored Jul 25, 2009
425 # * <tt>:subject</tt> - Preset the subject line of the email.
986c1a6 @dhh Deprecated UrlHelper#link_to_image and UrlHelper#link_to :post => tru…
dhh authored Oct 22, 2006
426 # * <tt>:body</tt> - Preset the body of the email.
e033b5d @lifo Merge docrails
lifo authored Jul 25, 2009
427 # * <tt>:cc</tt> - Carbon Copy addition recipients on the email.
428 # * <tt>:bcc</tt> - Blind Carbon Copy additional recipients on the email.
45db66d @dhh Added :encode option to mail_to that'll allow you to masquarede the e…
dhh authored Jan 24, 2005
429 #
f07d0e2 Enhance documentation and add examples for url_for. Closes #8227. [je…
Marcel Molina authored May 6, 2007
430 # ==== Examples
c98692a @clemens Removed handling of string parameter in link_to to have all URL gener…
clemens authored Jul 19, 2008
431 # mail_to "me@domain.com"
f07d0e2 Enhance documentation and add examples for url_for. Closes #8227. [je…
Marcel Molina authored May 6, 2007
432 # # => <a href="mailto:me@domain.com">me@domain.com</a>
d768ff1 @dhh Documentation fix #698
dhh authored Feb 23, 2005
433 #
c98692a @clemens Removed handling of string parameter in link_to to have all URL gener…
clemens authored Jul 19, 2008
434 # mail_to "me@domain.com", "My email", :encode => "javascript"
ea0d036 @miloops mail_to should use decodeURIcomponent instead of unescape to be utf f…
miloops authored Jul 31, 2008
435 # # => <script type="text/javascript">eval(decodeURIComponent('%64%6f%63...%27%29%3b'))</script>
f7c61b6 @dhh Added options to set cc, bcc, subject, and body for UrlHelper#mail_to #…
dhh authored Apr 2, 2005
436 #
c98692a @clemens Removed handling of string parameter in link_to to have all URL gener…
clemens authored Jul 19, 2008
437 # mail_to "me@domain.com", "My email", :encode => "hex"
f07d0e2 Enhance documentation and add examples for url_for. Closes #8227. [je…
Marcel Molina authored May 6, 2007
438 # # => <a href="mailto:%6d%65@%64%6f%6d%61%69%6e.%63%6f%6d">My email</a>
439 #
c98692a @clemens Removed handling of string parameter in link_to to have all URL gener…
clemens authored Jul 19, 2008
440 # mail_to "me@domain.com", nil, :replace_at => "_at_", :replace_dot => "_dot_", :class => "email"
f07d0e2 Enhance documentation and add examples for url_for. Closes #8227. [je…
Marcel Molina authored May 6, 2007
441 # # => <a href="mailto:me@domain.com" class="email">me_at_domain_dot_com</a>
986c1a6 @dhh Deprecated UrlHelper#link_to_image and UrlHelper#link_to :post => tru…
dhh authored Oct 22, 2006
442 #
dfc1285 @jeremy Deprecation: remove deprecated link_to_image and link_image_to method…
jeremy authored Mar 13, 2007
443 # mail_to "me@domain.com", "My email", :cc => "ccaddress@domain.com",
c98692a @clemens Removed handling of string parameter in link_to to have all URL gener…
clemens authored Jul 19, 2008
444 # :subject => "This is an example email"
f07d0e2 Enhance documentation and add examples for url_for. Closes #8227. [je…
Marcel Molina authored May 6, 2007
445 # # => <a href="mailto:me@domain.com?cc=ccaddress@domain.com&subject=This%20is%20an%20example%20email">My email</a>
db045db @dhh Initial
dhh authored Nov 24, 2004
446 def mail_to(email_address, name = nil, html_options = {})
dfac1ce @dhh Fixed that form helpers would treat string and symbol keys differentl…
dhh authored Mar 6, 2005
447 html_options = html_options.stringify_keys
dad60e7 @jeremy mail_to :encode => 'hex' also encodes the mailto: part of the href at…
jeremy authored Jan 28, 2007
448 encode = html_options.delete("encode").to_s
f7c61b6 @dhh Added options to set cc, bcc, subject, and body for UrlHelper#mail_to #…
dhh authored Apr 2, 2005
449 cc, bcc, subject, body = html_options.delete("cc"), html_options.delete("bcc"), html_options.delete("subject"), html_options.delete("body")
450
45db66d @dhh Added :encode option to mail_to that'll allow you to masquarede the e…
dhh authored Jan 24, 2005
451 string = ''
f7c61b6 @dhh Added options to set cc, bcc, subject, and body for UrlHelper#mail_to #…
dhh authored Apr 2, 2005
452 extras = ''
0cf1900 @josevalim Remove CGI.escape in function of Rack::Mount.escape
josevalim authored Jan 6, 2010
453 extras << "cc=#{Rack::Utils.escape(cc).gsub("+", "%20")}&" unless cc.nil?
454 extras << "bcc=#{Rack::Utils.escape(bcc).gsub("+", "%20")}&" unless bcc.nil?
455 extras << "body=#{Rack::Utils.escape(body).gsub("+", "%20")}&" unless body.nil?
456 extras << "subject=#{Rack::Utils.escape(subject).gsub("+", "%20")}&" unless subject.nil?
f7c61b6 @dhh Added options to set cc, bcc, subject, and body for UrlHelper#mail_to #…
dhh authored Apr 2, 2005
457 extras = "?" << extras.gsub!(/&?$/,"") unless extras.empty?
458
986c1a6 @dhh Deprecated UrlHelper#link_to_image and UrlHelper#link_to :post => tru…
dhh authored Oct 22, 2006
459 email_address = email_address.to_s
460
a53372c @dhh Added that UrlHelper#mail_to will now also encode the default link ti…
dhh authored Jul 2, 2005
461 email_address_obfuscated = email_address.dup
462 email_address_obfuscated.gsub!(/@/, html_options.delete("replace_at")) if html_options.has_key?("replace_at")
463 email_address_obfuscated.gsub!(/\./, html_options.delete("replace_dot")) if html_options.has_key?("replace_dot")
464
986c1a6 @dhh Deprecated UrlHelper#link_to_image and UrlHelper#link_to :post => tru…
dhh authored Oct 22, 2006
465 if encode == "javascript"
50b5c68 @js Ensure mail_to label is obfuscated for javascript encoding. [#294 sta…
js authored Jul 12, 2008
466 "document.write('#{content_tag("a", name || email_address_obfuscated, html_options.merge({ "href" => "mailto:"+email_address+extras }))}');".each_byte do |c|
8931a6e @jeremy Ruby 1.9 compat: url helper encoding
jeremy authored Dec 21, 2007
467 string << sprintf("%%%x", c)
45db66d @dhh Added :encode option to mail_to that'll allow you to masquarede the e…
dhh authored Jan 24, 2005
468 end
ea0d036 @miloops mail_to should use decodeURIcomponent instead of unescape to be utf f…
miloops authored Jul 31, 2008
469 "<script type=\"#{Mime::JS}\">eval(decodeURIComponent('#{string}'))</script>"
986c1a6 @dhh Deprecated UrlHelper#link_to_image and UrlHelper#link_to :post => tru…
dhh authored Oct 22, 2006
470 elsif encode == "hex"
dad60e7 @jeremy mail_to :encode => 'hex' also encodes the mailto: part of the href at…
jeremy authored Jan 28, 2007
471 email_address_encoded = ''
472 email_address_obfuscated.each_byte do |c|
473 email_address_encoded << sprintf("&#%d;", c)
474 end
475
476 protocol = 'mailto:'
477 protocol.each_byte { |c| string << sprintf("&#%d;", c) }
478
8931a6e @jeremy Ruby 1.9 compat: url helper encoding
jeremy authored Dec 21, 2007
479 email_address.each_byte do |c|
480 char = c.chr
481 string << (char =~ /\w/ ? sprintf("%%%x", c) : char)
45db66d @dhh Added :encode option to mail_to that'll allow you to masquarede the e…
dhh authored Jan 24, 2005
482 end
dad60e7 @jeremy mail_to :encode => 'hex' also encodes the mailto: part of the href at…
jeremy authored Jan 28, 2007
483 content_tag "a", name || email_address_encoded, html_options.merge({ "href" => "#{string}#{extras}" })
45db66d @dhh Added :encode option to mail_to that'll allow you to masquarede the e…
dhh authored Jan 24, 2005
484 else
a53372c @dhh Added that UrlHelper#mail_to will now also encode the default link ti…
dhh authored Jul 2, 2005
485 content_tag "a", name || email_address_obfuscated, html_options.merge({ "href" => "mailto:#{email_address}#{extras}" })
45db66d @dhh Added :encode option to mail_to that'll allow you to masquarede the e…
dhh authored Jan 24, 2005
486 end
db045db @dhh Initial
dhh authored Nov 24, 2004
487 end
488
f07d0e2 Enhance documentation and add examples for url_for. Closes #8227. [je…
Marcel Molina authored May 6, 2007
489 # True if the current request URI was generated by the given +options+.
490 #
491 # ==== Examples
ef9b6b5 @eandrejko modified current_page? to ignore extra parameters unless specified in…
eandrejko authored Oct 26, 2008
492 # Let's say we're in the <tt>/shop/checkout?order=desc</tt> action.
f07d0e2 Enhance documentation and add examples for url_for. Closes #8227. [je…
Marcel Molina authored May 6, 2007
493 #
494 # current_page?(:action => 'process')
495 # # => false
496 #
497 # current_page?(:controller => 'shop', :action => 'checkout')
498 # # => true
499 #
b80fa81 @chrisfinne Fix a syntax error in current_page?() that was prevent matches agains…
chrisfinne authored Feb 3, 2009
500 # current_page?(:controller => 'shop', :action => 'checkout', :order => 'asc')
501 # # => false
502 #
503 # current_page?(:action => 'checkout')
504 # # => true
505 #
506 # current_page?(:controller => 'library', :action => 'checkout')
507 # # => false
508 #
509 # Let's say we're in the <tt>/shop/checkout?order=desc&page=1</tt> action.
510 #
511 # current_page?(:action => 'process')
512 # # => false
513 #
514 # current_page?(:controller => 'shop', :action => 'checkout')
515 # # => true
516 #
517 # current_page?(:controller => 'shop', :action => 'checkout', :order => 'desc', :page=>'1')
518 # # => true
519 #
520 # current_page?(:controller => 'shop', :action => 'checkout', :order => 'desc', :page=>'2')
521 # # => false
522 #
523 # current_page?(:controller => 'shop', :action => 'checkout', :order => 'desc')
ef9b6b5 @eandrejko modified current_page? to ignore extra parameters unless specified in…
eandrejko authored Oct 26, 2008
524 # # => false
525 #
f07d0e2 Enhance documentation and add examples for url_for. Closes #8227. [je…
Marcel Molina authored May 6, 2007
526 # current_page?(:action => 'checkout')
527 # # => true
528 #
529 # current_page?(:controller => 'library', :action => 'checkout')
530 # # => false
761b18a @dhh Added current_page?(options) method to check if the url_for options p…
dhh authored Feb 17, 2005
531 def current_page?(options)
b80fa81 @chrisfinne Fix a syntax error in current_page?() that was prevent matches agains…
chrisfinne authored Feb 4, 2009
532 url_string = CGI.unescapeHTML(url_for(options))
1a750da @josh Make @controller an internal ivar in the view
josh authored Jan 22, 2010
533 request = controller.request
534 # We ignore any extra parameters in the request_uri if the
ef9b6b5 @eandrejko modified current_page? to ignore extra parameters unless specified in…
eandrejko authored Oct 26, 2008
535 # submitted url doesn't have any either. This lets the function
1a750da @josh Make @controller an internal ivar in the view
josh authored Jan 22, 2010
536 # work with things like ?order=asc
ef9b6b5 @eandrejko modified current_page? to ignore extra parameters unless specified in…
eandrejko authored Oct 26, 2008
537 if url_string.index("?")
538 request_uri = request.request_uri
539 else
540 request_uri = request.request_uri.split('?').first
541 end
fa619b0 @jeremy link_to_unless_current works with full URLs as well as paths. Closes #…
jeremy authored Jan 12, 2007
542 if url_string =~ /^\w+:\/\//
ef9b6b5 @eandrejko modified current_page? to ignore extra parameters unless specified in…
eandrejko authored Oct 26, 2008
543 url_string == "#{request.protocol}#{request.host_with_port}#{request_uri}"
fa619b0 @jeremy link_to_unless_current works with full URLs as well as paths. Closes #…
jeremy authored Jan 12, 2007
544 else
ef9b6b5 @eandrejko modified current_page? to ignore extra parameters unless specified in…
eandrejko authored Oct 26, 2008
545 url_string == request_uri
fa619b0 @jeremy link_to_unless_current works with full URLs as well as paths. Closes #…
jeremy authored Jan 12, 2007
546 end
761b18a @dhh Added current_page?(options) method to check if the url_for options p…
dhh authored Feb 17, 2005
547 end
548
db045db @dhh Initial
dhh authored Nov 24, 2004
549 private
392817c @erikstmartin updating link_to and button_to to support :remote => true and other o…
erikstmartin authored Jan 31, 2010
550 def convert_options_to_data_attributes(options, html_options)
551 html_options = {} if html_options.nil?
552 html_options = html_options.stringify_keys
553
554 if (options.is_a?(Hash) && options.key?('remote')) || (html_options.is_a?(Hash) && html_options.key?('remote'))
555 html_options['data-remote'] = 'true'
556 options.delete('remote') if options.is_a?(Hash)
557 html_options.delete('remote') if html_options.is_a?(Hash)
558 end
559
4f7a85d @josh Revert "Merge branch 'rails/master' into ujs"
josh authored Jan 30, 2010
560 confirm = html_options.delete("confirm")
561
562 if html_options.key?("popup")
563 ActiveSupport::Deprecation.warn(":popup has been deprecated", caller)
564 end
565
392817c @erikstmartin updating link_to and button_to to support :remote => true and other o…
erikstmartin authored Jan 31, 2010
566 method, href = html_options.delete("method"), html_options['href']
567
568 if confirm && method
569 add_confirm_to_attributes!(html_options, confirm)
570 add_method_to_attributes!(html_options, method)
571 elsif confirm
572 add_confirm_to_attributes!(html_options, confirm)
573 elsif method
574 add_method_to_attributes!(html_options, method)
4f7a85d @josh Revert "Merge branch 'rails/master' into ujs"
josh authored Jan 30, 2010
575 end
392817c @erikstmartin updating link_to and button_to to support :remote => true and other o…
erikstmartin authored Jan 31, 2010
576
577 html_options["data-url"] = options[:url] if options.is_a?(Hash) && options[:url]
578
579 html_options
4f7a85d @josh Revert "Merge branch 'rails/master' into ujs"
josh authored Jan 30, 2010
580 end
581
392817c @erikstmartin updating link_to and button_to to support :remote => true and other o…
erikstmartin authored Jan 31, 2010
582 def add_confirm_to_attributes!(html_options, confirm)
583 html_options["data-confirm"] = confirm if confirm
4f7a85d @josh Revert "Merge branch 'rails/master' into ujs"
josh authored Jan 30, 2010
584 end
585
392817c @erikstmartin updating link_to and button_to to support :remote => true and other o…
erikstmartin authored Jan 31, 2010
586 def add_method_to_attributes!(html_options, method)
48459c8 @josh Add rel=nofollow on non get remote links
josh authored Jan 30, 2010
587 html_options["rel"] = "nofollow" if method && method.to_s.downcase != "get"
392817c @erikstmartin updating link_to and button_to to support :remote => true and other o…
erikstmartin authored Jan 31, 2010
588 html_options["data-method"] = method if method
589 end
4f7a85d @josh Revert "Merge branch 'rails/master' into ujs"
josh authored Jan 30, 2010
590
392817c @erikstmartin updating link_to and button_to to support :remote => true and other o…
erikstmartin authored Jan 31, 2010
591 def options_for_javascript(options)
592 if options.empty?
593 '{}'
594 else
595 "{#{options.keys.map { |k| "#{k}:#{options[k]}" }.sort.join(', ')}}"
4f7a85d @josh Revert "Merge branch 'rails/master' into ujs"
josh authored Jan 30, 2010
596 end
392817c @erikstmartin updating link_to and button_to to support :remote => true and other o…
erikstmartin authored Jan 31, 2010
597 end
4f7a85d @josh Revert "Merge branch 'rails/master' into ujs"
josh authored Jan 30, 2010
598
392817c @erikstmartin updating link_to and button_to to support :remote => true and other o…
erikstmartin authored Jan 31, 2010
599 def array_or_string_for_javascript(option)
600 if option.kind_of?(Array)
601 "['#{option.join('\',\'')}']"
602 elsif !option.nil?
603 "'#{option}'"
4f7a85d @josh Revert "Merge branch 'rails/master' into ujs"
josh authored Jan 30, 2010
604 end
605 end
606
e033b5d @lifo Merge docrails
lifo authored Jul 25, 2009
607 # Processes the +html_options+ hash, converting the boolean
43c470f @dhh Added button_to as a form-based solution to deal with harmful actions…
dhh authored Jun 16, 2005
608 # attributes from true/false form into the form required by
609 # HTML/XHTML. (An attribute is considered to be boolean if
e033b5d @lifo Merge docrails
lifo authored Jul 25, 2009
610 # its name is listed in the given +bool_attrs+ array.)
43c470f @dhh Added button_to as a form-based solution to deal with harmful actions…
dhh authored Jun 16, 2005
611 #
e033b5d @lifo Merge docrails
lifo authored Jul 25, 2009
612 # More specifically, for each boolean attribute in +html_options+
43c470f @dhh Added button_to as a form-based solution to deal with harmful actions…
dhh authored Jun 16, 2005
613 # given as:
614 #
e033b5d @lifo Merge docrails
lifo authored Jul 25, 2009
615 # "attr" => bool_value
43c470f @dhh Added button_to as a form-based solution to deal with harmful actions…
dhh authored Jun 16, 2005
616 #
e033b5d @lifo Merge docrails
lifo authored Jul 25, 2009
617 # if the associated +bool_value+ evaluates to true, it is
43c470f @dhh Added button_to as a form-based solution to deal with harmful actions…
dhh authored Jun 16, 2005
618 # replaced with the attribute's name; otherwise the attribute is
e033b5d @lifo Merge docrails
lifo authored Jul 25, 2009
619 # removed from the +html_options+ hash. (See the XHTML 1.0 spec,
43c470f @dhh Added button_to as a form-based solution to deal with harmful actions…
dhh authored Jun 16, 2005
620 # section 4.5 "Attribute Minimization" for more:
621 # http://www.w3.org/TR/xhtml1/#h-4.5)
622 #
e033b5d @lifo Merge docrails
lifo authored Jul 25, 2009
623 # Returns the updated +html_options+ hash, which is also modified
43c470f @dhh Added button_to as a form-based solution to deal with harmful actions…
dhh authored Jun 16, 2005
624 # in place.
625 #
626 # Example:
627 #
628 # convert_boolean_attributes!( html_options,
629 # %w( checked disabled readonly ) )
630 def convert_boolean_attributes!(html_options, bool_attrs)
631 bool_attrs.each { |x| html_options[x] = x if html_options.delete(x) }
632 html_options
633 end
db045db @dhh Initial
dhh authored Nov 24, 2004
634 end
635 end
43c470f @dhh Added button_to as a form-based solution to deal with harmful actions…
dhh authored Jun 16, 2005
636 end
Something went wrong with that request. Please try again.