This error seems pretty bizarre. I''m using ActionMailer and am using a template in app/views/welcome_mailer/join.rhtml which has this line: <%= link_to :controller => ''group'', :action => ''join'', :group => @group.id, :ic => @code.code %> The error is: undefined method `url_for'' for #<WelcomeMailer: 0x2aaaad4fb470> I know the variables are OK because I''ve tested them. If I change the link_to to a url_for, I get the exact same error. Anyone know what''s the problem? All help is appreciated & thanks in advance! -Jason --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Jason Frankovitz wrote:> The error is: undefined method `url_for'' for #<WelcomeMailer: > 0x2aaaad4fb470> > > Anyone know what''s the problem? All help is appreciated & thanks in > advance!The problem is that the mailer does not have a controller to reference, which is needed for url_for. One way to solve this is by passing the controller to the mailer: def my_mailer_action(controller, *rest) @body[:controller] = controller end Then you should be able to use url_for. The only problem with this solution is if you are not sending e-mail from a controller. Dan Manges --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Jan 2, 2007, at 9:30 PM, Dan Manges wrote:> > Jason Frankovitz wrote: >> The error is: undefined method `url_for'' for #<WelcomeMailer: >> 0x2aaaad4fb470> >> >> Anyone know what''s the problem? All help is appreciated & thanks in >> advance! > > The problem is that the mailer does not have a controller to > reference, > which is needed for url_for. One way to solve this is by passing the > controller to the mailer: > > def my_mailer_action(controller, *rest) > @body[:controller] = controller > end > > Then you should be able to use url_for. The only problem with this > solution is if you are not sending e-mail from a controller. > > Dan Manges >Thanks for your reply Dan. It turns out I''m not using a controller: I only have a welcome_mailer model with a join method in it, and then the join.rhtml template with the link_to in it (I''m assuming that if I add your code into the model it won''t work). I also tried putting "helper ActionView::Helpers::UrlHelper" inside my WelcomeMailer class but that didn''t seem to help either. If anyone has another idea for how to get around this, please let me know. Thanks again, in advance! -Jason --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---