public
Fork of rails/rails
Description: Ruby on Rails
Homepage: http://rubyonrails.org
Clone URL: git://github.com/josh/rails.git
* Remove default_url_options from mailer generator
* Improve mailer documentation regarding generating URLs
* Add no_match to mailer generator to warn contributors about 
default_url_options
Signed-off-by: Joshua Peek <josh@joshpeek.com>
codyfauser (author)
Mon Apr 21 12:31:54 -0700 2008
josh (committer)
Mon Apr 21 12:31:54 -0700 2008
commit  4809dcc1b50330a04ec61dd1fef6cdba9892ac3d
tree    3f2a7863b5ee389b6fb1e7b3f2bde02b3c481062
parent  4ac33de4d61efe27454bbced7aece88604508bf1
...
73
74
75
76
 
 
 
 
 
77
78
79
80
 
 
 
81
82
83
84
85
86
87
88
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
89
90
 
 
 
 
91
92
93
...
73
74
75
 
76
77
78
79
80
81
 
 
 
82
83
84
85
 
 
 
 
 
 
 
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
 
102
103
104
105
106
107
108
0
@@ -73,21 +73,36 @@ module ActionMailer #:nodoc:
0
   # <%= truncate(note.body, 25) %>
0
   #
0
   #
0
- # = Generating URLs for mailer views
0
+ # = Generating URLs
0
+ #
0
+ # URLs can be generated in mailer views using <tt>url_for</tt> or named routes.
0
+ # Unlike controllers from Action Pack, the mailer instance doesn't have any context about the incoming request,
0
+ # so you'll need to provide all of the details needed to generate a URL.
0
   #
0
- # If your view includes URLs from the application, you need to use url_for in the mailing method instead of the view.
0
- # Unlike controllers from Action Pack, the mailer instance doesn't have any context about the incoming request. That's
0
- # why you need to jump this little hoop and supply all the details needed for the URL. Example:
0
+ # When using <tt>url_for</tt> you'll need to provide the <tt>:host</tt>, <tt>:controller</tt>, and <tt>:action</tt>:
0
+ #
0
+ # <%= url_for(:host => "example.com", :controller => "welcome", :action => "greeting") %>
0
   #
0
- # def signup_notification(recipient)
0
- # recipients recipient.email_address_with_name
0
- # from "system@example.com"
0
- # subject "New account information"
0
- # body :account => recipient,
0
- # :home_page => url_for(:host => "example.com", :controller => "welcome", :action => "greeting")
0
- # end
0
+ # When using named routes you only need to supply the <tt>:host</tt>:
0
+ #
0
+ # <%= users_url(:host => "example.com") %>
0
+ #
0
+ # You will want to avoid using the <tt>name_of_route_path</tt> form of named routes because it doesn't make sense to
0
+ # generate relative URLs in email messages.
0
+ #
0
+ # It is also possible to set a default host that will be used in all mailers by setting the <tt>:host</tt> option in
0
+ # the <tt>ActionMailer::Base.default_url_options</tt> hash as follows:
0
+ #
0
+ # ActionMailer::Base.default_url_options[:host] = "example.com"
0
+ #
0
+ # This can also be set as a configuration option in <tt>environment.rb</tt>:
0
+ #
0
+ # config.action_mailer.default_url_options = { :host => "example.com" }
0
   #
0
- # You can now access @home_page in the template and get http://example.com/welcome/greeting.
0
+ # If you do decide to set a default <tt>:host</tt> for your mailers you will want to use the
0
+ # <tt>:only_path => false</tt> option when using <tt>url_for</tt>. This will ensure that absolute URLs are generated because
0
+ # the <tt>url_for</tt> view helper will, by default, generate relative URLs when a <tt>:host</tt> option isn't
0
+ # explicitly provided.
0
   #
0
   # = Sending mail
0
   #
...
1
2
3
4
5
6
7
...
1
2
 
 
3
4
5
0
@@ -1,7 +1,5 @@
0
 class <%= class_name %> < ActionMailer::Base
0
   
0
- # change to your domain name
0
- default_url_options[:host] = 'example.com'
0
 <% for action in actions -%>
0
 
0
   def <%= action %>(sent_at = Time.now)
...
17
18
19
20
21
22
 
 
 
23
24
25
...
17
18
19
 
 
 
20
21
22
23
24
25
0
@@ -17,9 +17,9 @@ class RailsMailerGeneratorTest < GeneratorTestCase
0
           ],
0
           body.split("\n").map{|line| line.sub(' '*4, '') }
0
       end
0
-
0
- assert_match /^ default_url_options\[:host\] = 'example.com'$/m, model,
0
- 'model should include default_url_options :host declaration'
0
+
0
+ assert_no_match /(self.default_url_options =|default_url_options\[.*\] =)/, model,
0
+ 'individual mailer models should not set default_url_options because the options are shared by all mailers'
0
     end
0
     
0
     assert_generated_views_for :notifier, 'reset_password.erb'

Comments

    No one has commented yet.