0
# <%= truncate(note.body, 25) %>
0
- # = Generating URLs for mailer views
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
- # 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
+ # <%= url_for(:host => "example.com", :controller => "welcome", :action => "greeting") %>
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
+ # When using named routes you only need to supply the <tt>:host</tt>:
0
+ # <%= users_url(:host => "example.com") %>
0
- # You can now access @home_page in the template and get http://example.com/welcome/greeting.
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
+ # 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
+ # ActionMailer::Base.default_url_options[:host] = "example.com"
0
+ # This can also be set as a configuration option in <tt>environment.rb</tt>:
0
+ # config.action_mailer.default_url_options = { :host => "example.com" }
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.
Comments
No one has commented yet.