0
@@ -3,8 +3,8 @@ require 'action_view/helpers/javascript_helper'
0
module Helpers #:nodoc:
0
# Provides a set of methods for making links and getting URLs that
0
- # depend on the routing subsystem (see ActionController::Routing).
0
- # This allows you to use the same format for links in views
0
+ # depend on the routing subsystem (see ActionController::Routing).
0
+ # This allows you to use the same format for links in views
0
include JavaScriptHelper
0
@@ -33,8 +33,8 @@ module ActionView
0
# If you instead of a hash pass a record (like an Active Record or Active Resource) as the options parameter,
0
# you'll trigger the named route for that record. The lookup will happen on the name of the class. So passing
0
- # a Workshop object will attempt to use the workshop_path route. If you have a nested route, such as
0
- # admin_workshop_path you'll have to call that explicitly (it's impossible for url_for to guess that route).
0
+ # a Workshop object will attempt to use the workshop_path route. If you have a nested route, such as
0
+ # admin_workshop_path you'll have to call that explicitly (it's impossible for url_for to guess that route).
0
# <%= url_for(:action => 'index') %>
0
@@ -62,19 +62,33 @@ module ActionView
0
# <%= url_for(@workshop) %>
0
# # calls @workshop.to_s
0
+ # <%= url_for("http://www.example.com") %>
0
+ # # => http://www.example.com
0
+ # <%= url_for(:back) %>
0
+ # # if request.env["HTTP_REFERER"] is set to "http://www.example.com"
0
+ # # => http://www.example.com
0
+ # <%= url_for(:back) %>
0
+ # # if request.env["HTTP_REFERER"] is not set or is blank
0
+ # # => javascript:history.back()
0
def url_for(options = {})
0
options = { :only_path => options[:host].nil? }.update(options.symbolize_keys)
0
escape = options.key?(:escape) ? options.delete(:escape) : true
0
- url = @controller.send(:url_for, options)
0
+ @controller.send(:url_for, options)
0
+ @controller.request.env["HTTP_REFERER"] || 'javascript:history.back()'
0
-
url = polymorphic_path(options)
0
+
polymorphic_path(options)
0
escape ? escape_once(url) : url
0
@@ -116,8 +130,8 @@ module ActionView
0
# Note that if the user has JavaScript disabled, the request will fall back
0
# to using GET. If <tt>:href => '#'</tt> is used and the user has JavaScript disabled
0
- # clicking the link will have no effect. If you are relying on the POST
0
- # behavior, your should check for it in your controller's action by using the
0
+ # clicking the link will have no effect. If you are relying on the POST
0
+ # behavior, your should check for it in your controller's action by using the
0
# request object's methods for <tt>post?</tt>, <tt>delete?</tt> or <tt>put?</tt>.
0
# You can mix and match the +html_options+ with the exception of
0
@@ -141,8 +155,8 @@ module ActionView
0
# link_to "Profile", :controller => "profiles", :action => "show", :id => @profile
0
# # => <a href="/profiles/show/1">Profile</a>
0
# link_to "Profiles", profiles_path
0
# # => <a href="/profiles">Profiles</a>
0
@@ -197,9 +211,9 @@ module ActionView
0
# # => <a href="/images/9" onclick="window.open(this.href,'new_window_name','height=300,width=600');return false;">View Image</a>
0
# link_to "Delete Image", @image, :confirm => "Are you sure?", :method => :delete
0
- # # => <a href="/images/9" onclick="if (confirm('Are you sure?')) { var f = document.createElement('form');
0
+ # # => <a href="/images/9" onclick="if (confirm('Are you sure?')) { var f = document.createElement('form');
0
# f.style.display = 'none'; this.parentNode.appendChild(f); f.method = 'POST'; f.action = this.href;
0
- # var m = document.createElement('input'); m.setAttribute('type', 'hidden'); m.setAttribute('name', '_method');
0
+ # var m = document.createElement('input'); m.setAttribute('type', 'hidden'); m.setAttribute('name', '_method');
0
# m.setAttribute('value', 'delete'); f.appendChild(m);f.submit(); };return false;">Delete Image</a>
0
def link_to(*args, &block)
0
@@ -211,14 +225,7 @@ module ActionView
0
options = args.second || {}
0
html_options = args.third
0
- @controller.request.env["HTTP_REFERER"] || 'javascript:history.back()'
0
+ url = url_for(options)
0
html_options = html_options.stringify_keys
0
@@ -228,7 +235,7 @@ module ActionView
0
href_attr = "href=\"#{url}\"" unless href
0
"<a #{href_attr}#{tag_options}>#{name || url}</a>"
0
@@ -260,7 +267,7 @@ module ActionView
0
# * <tt>:confirm</tt> - This will add a JavaScript confirm
0
# prompt with the question specified. If the user accepts, the link is
0
# processed normally, otherwise no action is taken.
0
# <%= button_to "New", :action => "new" %>
0
# # => "<form method="post" action="/controller/new" class="button-to">
0
@@ -286,12 +293,12 @@ module ActionView
0
form_method = method.to_s == 'get' ? 'get' : 'post'
0
if form_method == 'post' && protect_against_forgery?
0
request_token_tag = tag(:input, :type => "hidden", :name => request_forgery_protection_token.to_s, :value => form_authenticity_token)
0
if confirm = html_options.delete("confirm")
0
html_options["onclick"] = "return #{confirm_javascript_function(confirm)};"
0
@@ -309,7 +316,7 @@ module ActionView
0
# Creates a link tag of the given +name+ using a URL created by the set of
0
# +options+ unless the current request URI is the same as the links, in
0
# which case only the name is returned (or the given block is yielded, if
0
- # one exists). You can give link_to_unless_current a block which will
0
+ # one exists). You can give link_to_unless_current a block which will
0
# specialize the default behavior (e.g., show a "Start Here" link rather
0
# than the link's text).
0
@@ -336,13 +343,13 @@ module ActionView
0
# The implicit block given to link_to_unless_current is evaluated if the current
0
- # action is the action given. So, if we had a comments page and wanted to render a
0
+ # action is the action given. So, if we had a comments page and wanted to render a
0
# "Go Back" link instead of a link to the comments page, we could do something like this...
0
# link_to_unless_current("Comment", { :controller => 'comments', :action => 'new}) do
0
- # link_to("Go back", { :controller => 'posts', :action => 'index' })
0
+ # link_to("Go back", { :controller => 'posts', :action => 'index' })
0
def link_to_unless_current(name, options = {}, html_options = {}, &block)
0
link_to_unless current_page?(options), name, options, html_options, &block
0
@@ -359,10 +366,10 @@ module ActionView
0
# # If the user is logged in...
0
# # => <a href="/controller/reply/">Reply</a>
0
# link_to_unless(@current_user.nil?, "Reply", { :action => "reply" }) do |name|
0
# link_to(name, { :controller => "accounts", :action => "signup" })
0
# # If the user is logged in...
0
# # => <a href="/controller/reply/">Reply</a>
0
@@ -391,10 +398,10 @@ module ActionView
0
# # If the user isn't logged in...
0
# # => <a href="/sessions/new/">Login</a>
0
# link_to_if(@current_user.nil?, "Login", { :controller => "sessions", :action => "new" }) do
0
# link_to(@current_user.login, { :controller => "accounts", :action => "show", :id => @current_user })
0
# # If the user isn't logged in...
0
# # => <a href="/sessions/new/">Login</a>
0
@@ -431,20 +438,20 @@ module ActionView
0
# * <tt>:bcc</tt> - Blind Carbon Copy additional recipients on the email.
0
- # mail_to "me@domain.com"
0
+ # mail_to "me@domain.com"
0
# # => <a href="mailto:me@domain.com">me@domain.com</a>
0
- # mail_to "me@domain.com", "My email", :encode => "javascript"
0
+ # mail_to "me@domain.com", "My email", :encode => "javascript"
0
# # => <script type="text/javascript">eval(unescape('%64%6f%63...%6d%65%6e'))</script>
0
- # mail_to "me@domain.com", "My email", :encode => "hex"
0
+ # mail_to "me@domain.com", "My email", :encode => "hex"
0
# # => <a href="mailto:%6d%65@%64%6f%6d%61%69%6e.%63%6f%6d">My email</a>
0
- # mail_to "me@domain.com", nil, :replace_at => "_at_", :replace_dot => "_dot_", :class => "email"
0
+ # mail_to "me@domain.com", nil, :replace_at => "_at_", :replace_dot => "_dot_", :class => "email"
0
# # => <a href="mailto:me@domain.com" class="email">me_at_domain_dot_com</a>
0
# mail_to "me@domain.com", "My email", :cc => "ccaddress@domain.com",
0
- # :subject => "This is an example email"
0
+ # :subject => "This is an example email"
0
# # => <a href="mailto:me@domain.com?cc=ccaddress@domain.com&subject=This%20is%20an%20example%20email">My email</a>
0
def mail_to(email_address, name = nil, html_options = {})
0
html_options = html_options.stringify_keys
Comments
No one has commented yet.