Hi, railers. I need an advice from you. I am using ActiveMailer and I want to write some application url to mail. Mail contains text something like this "If you want to confirm subscription please click this link ..." Well, I am trying to add following code to *.rthml file but it does not work <%= UrlHelper::url_for(:action=>''confirm_authorization'',:id=>@user.auth_code) %> Where better of all (or how) calculate urls?? There is error from mailer test. 1) Error: test_signup(NotificationsTest): ActionView::TemplateError: uninitialized constant UrlHelper On line #5 of /app/views/notifications/signup.rhtml 2: 3: Thank you for registering an account. To confirm your account, click the link below: 4: 5: <%= UrlHelper::url_for(:action=>''confirm_authorization'',:id=>@ user.auth_code) %> 6: 7: If you have not signed up for an account or believe this email is incorrect, click the link below: 8: c:/progra~1/Ruby/lib/ruby/gems/1.8/gems/activesupport-1.1.1/lib/active_support/dependencies.rb:186:in `const_missing'' D:/work/darkthrone/darkthrone-ruby/trunk/app/views/notifications/signup.rhtml:5:in `__compiled_method_2'' -- anatol _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
On 13.9.2005, at 11.22, Anatol Pomozov wrote:> Hi, railers. > > I need an advice from you. > I am using ActiveMailer and I want to write some application url to > mail. > Mail contains text something like this > "If you want to confirm subscription please click this link ..." > Well, I am trying to add following code to *.rthml file but it does > not work > <%= UrlHelper::url_for > (:action=>''confirm_authorization'',:id=>@user.auth_code) %> > > Where better of all (or how) calculate urls??Just use url_for(...). You shouldn''t specify the module. This holds for all helper usage in templates. //jarkko> > > There is error from mailer test. > > > 1) Error: > test_signup(NotificationsTest): > ActionView::TemplateError: uninitialized constant UrlHelper > On line #5 of /app/views/notifications/signup.rhtml > > 2: > 3: Thank you for registering an account. To confirm your > account, click the link below: > 4: > 5: <%= UrlHelper::url_for > (:action=>''confirm_authorization'',:id=>@user.auth_code) %> > 6: > 7: If you have not signed up for an account or believe this > email is incorrect, click the link below: > 8: > > c:/progra~1/Ruby/lib/ruby/gems/1.8/gems/activesupport-1.1.1/lib/ > active_support/dependencies.rb:186:in `const_missing'' > D:/work/darkthrone/darkthrone-ruby/trunk/app/views/ > notifications/signup.rhtml:5:in `__compiled_method_2'' > > -- > anatol > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >_______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
Hi. It also does not working. If you put url_for() into mail template it gives following error. I don''t like phrase "undefined method `url_for'' for #<Notifications:0x37eef68>". Notifications is my activemailer model. I could use url_for right in controller but it seems odd for me, because formatting url is more view responsibility than logic. Or imagine if i need to write 10 urls to mail (i.e http://localhost/remove-accout/:id, ../add_buddy/:id, ..), what I need to do? Create 10 parameters method in ActiveMailer model and pass all those urls? Well, I prefer to format url right in template. PS. I am using edge rails. 1) Error: test_signup(NotificationsTest): ActionView::TemplateError: undefined method `url_for'' for #<Notifications:0x37eef68> On line #5 of /app/views/notifications/signup.rhtml 2: 3: Thank you for registering an account with Dark Throne. To confirm your account, click the link below: 4: 5: <%= url_for(:action=>''confirm_authorization'',:id=>@user.auth_code) %> 6: 7: If you have not signed up for an account with Dark Throne or believe this email is incorrect, click the link below: 8: c:/progra~1/Ruby/lib/ruby/gems/1.8/gems/actionpack-1.9.1/lib/action_view/helpers/url_helper.rb:18:in `send'' c:/progra~1/Ruby/lib/ruby/gems/1.8/gems/actionpack-1.9.1/lib/action_view/helpers/url_helper.rb:18:in `url_for'' D:/work/darkthrone/darkthrone-ruby/trunk/app/views/notifications/signup.rhtml:5:in `__compiled_method_2'' c:/progra~1/Ruby/lib/ruby/gems/1.8/gems/actionpack-1.9.1/lib/action_view/base.rb:249:in `send'' c:/progra~1/Ruby/lib/ruby/gems/1.8/gems/actionpack-1.9.1/lib/action_view/base.rb:249:in `compile_and_render_template'' c:/progra~1/Ruby/lib/ruby/gems/1.8/gems/actionpack-1.9.1/lib/action_view/base.rb:220:in `render_template'' Just use url_for(...). You shouldn''t specify the module. This holds> for all helper usage in templates. > > //jarkko >-- anatol _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
Hi, Is it not the case that you would use link_to in your view, rather than url_for?> <%= link_to(''string to > show'', :action=>''confirm_authorization'',:id=>@user.auth_code) %>Rgds, Steve On 13 Sep 2005, at 10:30, Anatol Pomozov wrote:> Hi. > > It also does not working. If you put url_for() into mail template > it gives following error. > I don''t like phrase "undefined method `url_for'' for #<Notifications: > 0x37eef68>". Notifications is my activemailer model. > > I could use url_for right in controller but it seems odd for me, > because formatting url is more view responsibility than logic. Or > imagine if i need to write 10 urls to mail (i.e http://localhost/ > remove-accout/:id, ../add_buddy/:id, ..), what I need to do? Create > 10 parameters method in ActiveMailer model and pass all those urls? > Well, I prefer to format url right in template. > > PS. I am using edge rails. > > > 1) Error: > test_signup(NotificationsTest): > ActionView::TemplateError: undefined method `url_for'' for > #<Notifications:0x37eef68> > On line #5 of /app/views/notifications/signup.rhtml > > 2: > 3: Thank you for registering an account with Dark Throne. To > confirm your account, click the link below: > 4: > 5: <%= url_for > (:action=>''confirm_authorization'',:id=>@user.auth_code) %> > 6: > 7: If you have not signed up for an account with Dark Throne or > believe this email is incorrect, click the link below: > 8: > > c:/progra~1/Ruby/lib/ruby/gems/1.8/gems/actionpack-1.9.1/lib/ > action_view/helpers/url_helper.rb:18:in `send'' > c:/progra~1/Ruby/lib/ruby/gems/1.8/gems/actionpack-1.9.1/lib/ > action_view/helpers/url_helper.rb:18:in `url_for'' > D:/work/darkthrone/darkthrone-ruby/trunk/app/views/ > notifications/signup.rhtml:5:in `__compiled_method_2'' > c:/progra~1/Ruby/lib/ruby/gems/1.8/gems/actionpack-1.9.1/lib/ > action_view/base.rb:249:in `send'' > c:/progra~1/Ruby/lib/ruby/gems/1.8/gems/actionpack-1.9.1/lib/ > action_view/base.rb:249:in `compile_and_render_template'' > c:/progra~1/Ruby/lib/ruby/gems/1.8/gems/actionpack-1.9.1/lib/ > action_view/base.rb:220:in `render_template'' > > > Just use url_for(...). You shouldn''t specify the module. This holds > for all helper usage in templates. > > //jarkko > > -- > anatol > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >_______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
I think that as ActionMailer templates are not evaluated in context of a controller, url_for and link_to will not work regardeless of syntax. I got around this problem by generating the sent URL in the controller via url_for. Then pass it to ActionMailer as string. I''m interested in a better solution. hope it helps, Zsombor -- Company - http://primalgrasp.com Thoughts - http://deezsombor.blogspot.com
On 13.9.2005, at 13.02, Dee Zsombor wrote:> I think that as ActionMailer templates are not evaluated in context > of a > controller, url_for and link_to will not work regardeless of syntax.Ah, bummer, you''re right. I also used parameters for this: class LoginMailer < ActionMailer::Base def register_request(recipients, client, approve_url) .. end end And in the template: <%= @approve_url %> Then I can call the delivery method in a controller like this: @approve_url = url_for :controller => "admin", :action => "approve_user", :id => @client.id LoginMailer.deliver_register_request(@recipients, @client, @approve_url) hth, //jarkko> > I got around this problem by generating the sent URL in the > controller via > url_for. Then pass it to ActionMailer as string. I''m interested in a > better solution. > > hope it helps, > Zsombor > > -- > Company - http://primalgrasp.com > Thoughts - http://deezsombor.blogspot.com > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails > >_______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
Thanks everyone for responses. Seems that create url in controller is only solution. Anyway I would prefer to have some of ActionPack helpers accessible in ActiveTemplate view just like plain in *.rthml view. I think generating application url in mail is a widely used and I would like to see this operation simpler. Forgive me if i misunderstood rails zen and if it is "right" when ActiveMailer view nothing knows about HTTP request and controllers. On 9/13/05, Jarkko Laine <jarkko-k1O+Gnc6WpmsTnJN9+BGXg@public.gmane.org> wrote:> > > On 13.9.2005, at 13.02, Dee Zsombor wrote: > > > I think that as ActionMailer templates are not evaluated in context > > of a > > controller, url_for and link_to will not work regardeless of syntax. > > Ah, bummer, you''re right. I also used parameters for this: > > class LoginMailer < ActionMailer::Base > > def register_request(recipients, client, approve_url) > .. > end > end > > And in the template: > <%= @approve_url %> > > Then I can call the delivery method in a controller like this: > @approve_url = url_for :controller => "admin", :action > => "approve_user", :id => @client.id <http://client.id> > LoginMailer.deliver_register_request(@recipients, > @client, @approve_url) > > hth, > //jarkko > > > > > > I got around this problem by generating the sent URL in the > > controller via > > url_for. Then pass it to ActionMailer as string. I''m interested in a > > better solution. >-- anatol _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
On Sep 13, 2005, at 4:45 AM, Anatol Pomozov wrote:> Thanks everyone for responses. > Seems that create url in controller is only solution. Anyway I > would prefer to have some of ActionPack helpers accessible in > ActiveTemplate view just like plain in *.rthml view. I think > generating application url in mail is a widely used and I would > like to see this operation simpler. > Forgive me if i misunderstood rails zen and if it is "right" when > ActiveMailer view nothing knows about HTTP request and controllers.Please see: http://wiki.rubyonrails.com/rails/show/ HowtoUseUrlHelpersWithActionMailer for more about why this can''t "just work", and how to easily make it work. - Jamis> > > On 9/13/05, Jarkko Laine <jarkko-k1O+Gnc6WpmsTnJN9+BGXg@public.gmane.org> wrote: > On 13.9.2005, at 13.02, Dee Zsombor wrote: > > > I think that as ActionMailer templates are not evaluated in context > > of a > > controller, url_for and link_to will not work regardeless of syntax. > > Ah, bummer, you''re right. I also used parameters for this: > > class LoginMailer < ActionMailer::Base > > def register_request(recipients, client, approve_url) > .. > end > end > > And in the template: > <%= @approve_url %> > > Then I can call the delivery method in a controller like this: > @approve_url = url_for :controller => "admin", :action > => "approve_user", :id => @client.id > LoginMailer.deliver_register_request(@recipients, > @client, @approve_url) > > hth, > //jarkko > > > > > > I got around this problem by generating the sent URL in the > > controller via > > url_for. Then pass it to ActionMailer as string. I''m interested in a > > better solution. > > -- > anatol > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
Unfortunately it does not work for me. This is my model class Notifications < ActionMailer::Base SYSTEM_EMAIL = ''Dark Throne System Email <donotreply-dTlVyljHlJfz1n+OaKNE4w@public.gmane.org>'' helper ActionView::Helpers::UrlHelper def signup(user, confirm_link, remove_link) @subject = ''Thank you for registering'' @body[''user''] = user @recipients = user.email @from = SYSTEM_EMAIL end end This is mailer view Dear, <%= @user.firstname %> <%= @user.lastname %> Thank you for registering an account. To confirm your account, click the link below: <%= url_for(:action=>''confirm_authorization'',:id=>@user.auth_code) %> If you have not signed up for an account or believe this email is incorrect, click the link below: <%= url_for(:action=>''remove_authorization'',:id=>@user.auth_code) %> And I still got a error 1) Error: test_signup(NotificationsTest): ActionView::TemplateError: undefined method `url_for'' for #<Notifications:0x37eef98> On line #5 of /app/views/notifications/signup.rhtml 2: 3: Thank you for registering an account with. To confirm your account, click the link below: 4: 5: <%= url_for(:action=>''confirm_authorization'',:id=>@user.auth_code) %> 6: 7: If you have not signed up for an account with or believe this email is incorrect, click the link below: 8: c:/progra~1/Ruby/lib/ruby/gems/1.8/gems/actionpack-1.9.1/lib/action_view/helpers/url_helper.rb:18:in `send'' c:/progra~1/Ruby/lib/ruby/gems/1.8/gems/actionpack-1.9.1/lib/action_view/helpers/url_helper.rb:18:in `url_for'' D:/work/darkthrone/darkthrone-ruby/trunk/app/views/notifications/signup.rhtml:5:in `__compiled_method_2'' c:/progra~1/Ruby/lib/ruby/gems/1.8/gems/actionpack-1.9.1/lib/action_view/base.rb:249:in `send'' c:/progra~1/Ruby/lib/ruby/gems/1.8/gems/actionpack-1.9.1/lib/action_view/base.rb:249:in `compile_and_render_template'' c:/progra~1/Ruby/lib/ruby/gems/1.8/gems/actionpack-1.9.1/lib/action_view/base.rb:220:in `render_template'' c:/progra~1/Ruby/lib/ruby/gems/1.8/gems/actionpack-1.9.1/lib/action_view/base.rb:181:in `render_file'' c:/progra~1/Ruby/lib/ruby/gems/1.8/gems/actionpack-1.9.1/lib/action_view/base.rb:202:in `render'' I am using edge rails. What''s wrong with my code?? On 9/13/05, Jamis Buck <jamis-uHoyYlH2B+GakBO8gow8eQ@public.gmane.org> wrote:> > On Sep 13, 2005, at 4:45 AM, Anatol Pomozov wrote: > > > Thanks everyone for responses. > > Seems that create url in controller is only solution. Anyway I > > would prefer to have some of ActionPack helpers accessible in > > ActiveTemplate view just like plain in *.rthml view. I think > > generating application url in mail is a widely used and I would > > like to see this operation simpler. > > Forgive me if i misunderstood rails zen and if it is "right" when > > ActiveMailer view nothing knows about HTTP request and controllers. > > Please see: > > http://wiki.rubyonrails.com/rails/show/ > HowtoUseUrlHelpersWithActionMailer > > for more about why this can''t "just work", and how to easily make it > work. > > - Jamis > > > > > > > On 9/13/05, Jarkko Laine <jarkko-k1O+Gnc6WpmsTnJN9+BGXg@public.gmane.org> wrote: > > On 13.9.2005, at 13.02, Dee Zsombor wrote: > > > > > I think that as ActionMailer templates are not evaluated in context > > > of a > > > controller, url_for and link_to will not work regardeless of syntax. > > > > Ah, bummer, you''re right. I also used parameters for this: > > > > class LoginMailer < ActionMailer::Base > > > > def register_request(recipients, client, approve_url) > > .. > > end > > end > > > > And in the template: > > <%= @approve_url %> > > > > Then I can call the delivery method in a controller like this: > > @approve_url = url_for :controller => "admin", :action > > => "approve_user", :id => @client.id <http://client.id> > > LoginMailer.deliver_register_request(@recipients, > > @client, @approve_url) > > > > hth, > > //jarkko > > > > > > > > > > I got around this problem by generating the sent URL in the > > > controller via > > > url_for. Then pass it to ActionMailer as string. I''m interested in a > > > better solution. > > > > -- > > anatol > > _______________________________________________ > > Rails mailing list > > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > >-- anatol _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
On 13.9.2005, at 18.54, Anatol Pomozov wrote:> Unfortunately it does not work for me. > > This is my model > > class Notifications < ActionMailer::Base > SYSTEM_EMAIL = ''Dark Throne System Email > <donotreply-dTlVyljHlJfz1n+OaKNE4w@public.gmane.org>'' > > helper ActionView::Helpers::UrlHelper > > def signup(user, confirm_link, remove_link) > @subject = ''Thank you for registering'' > @body[''user''] = user > @recipients = user.email > @from = SYSTEM_EMAIL > end > end > > This is mailer view > > Dear, <%= @user.firstname %> <%= @user.lastname %> > Thank you for registering an account. To confirm your account, > click the link below: > <%= url_for(:action=>''confirm_authorization'',:id=>@user.auth_code) %> > If you have not signed up for an account or believe this email is > incorrect, click the link below: > <%= url_for(:action=>''remove_authorization'',:id=>@user.auth_code) %> > > And I still got a error > > What''s wrong with my code??You''re confusing two approaches. If you provide the two links as parameters, you should use them directly in the template (see my previous post for how). If you want to use the approach Jamis described (and use the helper in your mail template), you need to give the controller as a parameter to the action. So not: def signup(user, confirm_link, remove_link) ...but: def signup(controller, user) This whole process is described in the wiki page Jamis referred to. //jarkko> > > > On 9/13/05, Jamis Buck <jamis-uHoyYlH2B+GakBO8gow8eQ@public.gmane.org> wrote: > On Sep 13, 2005, at 4:45 AM, Anatol Pomozov wrote: > > > Thanks everyone for responses. > > Seems that create url in controller is only solution. Anyway I > > would prefer to have some of ActionPack helpers accessible in > > ActiveTemplate view just like plain in *.rthml view. I think > > generating application url in mail is a widely used and I would > > like to see this operation simpler. > > Forgive me if i misunderstood rails zen and if it is "right" when > > ActiveMailer view nothing knows about HTTP request and controllers. > > Please see: > > http://wiki.rubyonrails.com/rails/show/ > HowtoUseUrlHelpersWithActionMailer > > for more about why this can''t "just work", and how to easily make it > work. > > - Jamis > > > > > > > On 9/13/05, Jarkko Laine <jarkko-k1O+Gnc6WpmsTnJN9+BGXg@public.gmane.org > wrote: > > On 13.9.2005, at 13.02, Dee Zsombor wrote: > > > > > I think that as ActionMailer templates are not evaluated in > context > > > of a > > > controller, url_for and link_to will not work regardeless of > syntax. > > > > Ah, bummer, you''re right. I also used parameters for this: > > > > class LoginMailer < ActionMailer::Base > > > > def register_request(recipients, client, approve_url) > > .. > > end > > end > > > > And in the template: > > <%= @approve_url %> > > > > Then I can call the delivery method in a controller like this: > > @approve_url = url_for :controller => "admin", :action > > => "approve_user", :id => @client.id > > LoginMailer.deliver_register_request(@recipients, > > @client, @approve_url) > > > > hth, > > //jarkko > > > > > > > > > > I got around this problem by generating the sent URL in the > > > controller via > > > url_for. Then pass it to ActionMailer as string. I''m interested > in a > > > better solution. > > > > -- > > anatol > > _______________________________________________ > > Rails mailing list > > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > > > > > -- > anatol > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >_______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
OK. It works. Thanks. But... How to test it?? I could not catch where I to find Controller instance in my NotificationsTest.. On 9/13/05, Jarkko Laine <jarkko-k1O+Gnc6WpmsTnJN9+BGXg@public.gmane.org> wrote:> > > On 13.9.2005, at 18.54, Anatol Pomozov wrote: > > Unfortunately it does not work for me. > > This is my model > > class Notifications < ActionMailer::Base > SYSTEM_EMAIL = ''Dark Throne System Email <donotreply-dTlVyljHlJfz1n+OaKNE4w@public.gmane.org>'' > > helper ActionView::Helpers::UrlHelper > > def signup(user, confirm_link, remove_link) > @subject = ''Thank you for registering'' > @body[''user''] = user > @recipients = user.email > @from = SYSTEM_EMAIL > end > end > > This is mailer view > > Dear, <%= @user.firstname %> <%= @user.lastname %> > Thank you for registering an account. To confirm your account, click the > link below: > <%= url_for(:action=>''confirm_authorization'',:id=>@user.auth_code) %> > If you have not signed up for an account or believe this email is > incorrect, click the link below: > <%= url_for(:action=>''remove_authorization'',:id=>@user.auth_code) %> > > And I still got a error > > What''s wrong with my code?? > > > You''re confusing two approaches. If you provide the two links as > parameters, you should use them directly in the template (see my previous > post for how). If you want to use the approach Jamis described (and use the > helper in your mail template), you need to give the controller as a > parameter to the action. > > So not: > def signup(user, confirm_link, remove_link) > > ...but: > def signup(controller, user) > > This whole process is described in the wiki page Jamis referred to. > > //jarkko > > > > > > On 9/13/05, Jamis Buck <jamis-uHoyYlH2B+GakBO8gow8eQ@public.gmane.org> wrote: > > > > On Sep 13, 2005, at 4:45 AM, Anatol Pomozov wrote: > > > > > Thanks everyone for responses. > > > Seems that create url in controller is only solution. Anyway I > > > would prefer to have some of ActionPack helpers accessible in > > > ActiveTemplate view just like plain in *.rthml view. I think > > > generating application url in mail is a widely used and I would > > > like to see this operation simpler. > > > Forgive me if i misunderstood rails zen and if it is "right" when > > > ActiveMailer view nothing knows about HTTP request and controllers. > > > > Please see: > > > > http://wiki.rubyonrails.com/rails/show/ > > HowtoUseUrlHelpersWithActionMailer > > > > for more about why this can''t "just work", and how to easily make it > > work. > > > > - Jamis > > > > > > > > > > > On 9/13/05, Jarkko Laine <jarkko-k1O+Gnc6WpmsTnJN9+BGXg@public.gmane.org > wrote: > > > On 13.9.2005, at 13.02, Dee Zsombor wrote: > > > > > > > I think that as ActionMailer templates are not evaluated in context > > > > of a > > > > controller, url_for and link_to will not work regardeless of syntax. > > > > > > > > Ah, bummer, you''re right. I also used parameters for this: > > > > > > class LoginMailer < ActionMailer::Base > > > > > > def register_request(recipients, client, approve_url) > > > .. > > > end > > > end > > > > > > And in the template: > > > <%= @approve_url %> > > > > > > Then I can call the delivery method in a controller like this: > > > @approve_url = url_for :controller => "admin", :action > > > => "approve_user", :id => @client.id <http://client.id> > > > LoginMailer.deliver_register_request(@recipients, > > > @client, @approve_url) > > > > > > hth, > > > //jarkko > > > > > > > > > > > > > > I got around this problem by generating the sent URL in the > > > > controller via > > > > url_for. Then pass it to ActionMailer as string. I''m interested in a > > > > > > better solution. > > > > > > -- > > > anatol > > > _______________________________________________ > > > Rails mailing list > > > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > > > > > > > > -- > anatol_______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails > > > >-- anatol _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
On Sep 13, 2005, at 11:58 AM, Anatol Pomozov wrote:> OK. It works. Thanks. > > But... How to test it?? I could not catch where I to find > Controller instance in my NotificationsTest..Just instantiate one: Notifications.deliver_signup(ApplicationController.new, ...) - Jamis> > On 9/13/05, Jarkko Laine < jarkko-k1O+Gnc6WpmsTnJN9+BGXg@public.gmane.org> wrote: > On 13.9.2005, at 18.54, Anatol Pomozov wrote: > >> Unfortunately it does not work for me. >> >> This is my model >> >> class Notifications < ActionMailer::Base >> SYSTEM_EMAIL = ''Dark Throne System Email < >> donotreply-dTlVyljHlJfz1n+OaKNE4w@public.gmane.org>'' >> >> helper ActionView::Helpers::UrlHelper >> >> def signup(user, confirm_link, remove_link) >> @subject = ''Thank you for registering'' >> @body[''user''] = user >> @recipients = user.email >> @from = SYSTEM_EMAIL >> end >> end >> >> This is mailer view >> >> Dear, <%= @ user.firstname %> <%= @user.lastname %> >> Thank you for registering an account. To confirm your account, >> click the link below: >> <%= url_for(:action=>''confirm_authorization'',:id=>@user.auth_code) %> >> If you have not signed up for an account or believe this email is >> incorrect, click the link below: >> <%= url_for(:action=>''remove_authorization'',:id=>@user.auth_code) %> >> >> And I still got a error >> >> What''s wrong with my code?? > > You''re confusing two approaches. If you provide the two links as > parameters, you should use them directly in the template (see my > previous post for how). If you want to use the approach Jamis > described (and use the helper in your mail template), you need to > give the controller as a parameter to the action. > > So not: > def signup(user, confirm_link, remove_link) > > ...but: > def signup(controller, user) > > This whole process is described in the wiki page Jamis referred to. > > //jarkko > > >> >> >> >> On 9/13/05, Jamis Buck <jamis-uHoyYlH2B+GakBO8gow8eQ@public.gmane.org > wrote: On Sep 13, >> 2005, at 4:45 AM, Anatol Pomozov wrote: >> >> > Thanks everyone for responses. >> > Seems that create url in controller is only solution. Anyway I >> > would prefer to have some of ActionPack helpers accessible in >> > ActiveTemplate view just like plain in *.rthml view. I think >> > generating application url in mail is a widely used and I would >> > like to see this operation simpler. >> > Forgive me if i misunderstood rails zen and if it is "right" when >> > ActiveMailer view nothing knows about HTTP request and controllers. >> >> Please see: >> >> http://wiki.rubyonrails.com/rails/show/ >> HowtoUseUrlHelpersWithActionMailer >> >> for more about why this can''t "just work", and how to easily make it >> work. >> >> - Jamis >> >> > >> > >> > On 9/13/05, Jarkko Laine < jarkko-k1O+Gnc6WpmsTnJN9+BGXg@public.gmane.org > wrote: >> > On 13.9.2005, at 13.02, Dee Zsombor wrote: >> > >> > > I think that as ActionMailer templates are not evaluated in >> context >> > > of a >> > > controller, url_for and link_to will not work regardeless of >> syntax. >> > >> > Ah, bummer, you''re right. I also used parameters for this: >> > >> > class LoginMailer < ActionMailer::Base >> > >> > def register_request(recipients, client, approve_url) >> > .. >> > end >> > end >> > >> > And in the template: >> > <%= @approve_url %> >> > >> > Then I can call the delivery method in a controller like this: >> > @approve_url = url_for :controller => "admin", :action >> > => "approve_user", :id => @client.id >> > LoginMailer.deliver_register_request(@recipients, >> > @client, @approve_url) >> > >> > hth, >> > //jarkko >> > >> > >> > > >> > > I got around this problem by generating the sent URL in the >> > > controller via >> > > url_for. Then pass it to ActionMailer as string. I''m >> interested in a >> > > better solution. >> > >> > -- >> > anatol >> > _______________________________________________ >> > Rails mailing list >> > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org >> > http://lists.rubyonrails.org/mailman/listinfo/rails >> > >> >> >> >> >> -- >> anatol >> _______________________________________________ >> Rails mailing list >> Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org >> http://lists.rubyonrails.org/mailman/listinfo/rails >> > > > > > > -- > anatol > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
I got an error. 1) Error: test_signup(NotificationsTest): ActionView::TemplateError: undefined method `rewrite'' for nil:NilClass On line #5 of /app/views/notifications/signup.rhtml 2: 3: Thank you for registering an account with. To confirm your account, click the link below: 4: 5: <%= url_for(:action=>''confirm_authorization'',:id=>@user.auth_code) %> 6: 7: If you have not signed up for an account with or believe this email is incorrect, click the link below: 8: c:/progra~1/Ruby/lib/ruby/gems/1.8/gems/activesupport-1.1.1/lib/active_support/whiny_nil.rb:30:in `method_missing'' c:/progra~1/Ruby/lib/ruby/gems/1.8/gems/actionpack-1.9.1/lib/action_controller/base.rb:440:in `url_for'' c:/progra~1/Ruby/lib/ruby/gems/1.8/gems/actionpack-1.9.1/lib/action_view/helpers/url_helper.rb:18:in `send'' c:/progra~1/Ruby/lib/ruby/gems/1.8/gems/actionpack-1.9.1/lib/action_view/helpers/url_helper.rb:18:in `url_for'' D:/work/darkthrone/darkthrone-ruby/trunk/app/views/notifications/signup.rhtml:5:in `__compiled_method_2'' c:/progra~1/Ruby/lib/ruby/gems/1.8/gems/actionpack-1.9.1/lib/action_view/base.rb:249:in `send'' c:/progra~1/Ruby/lib/ruby/gems/1.8/gems/actionpack-1.9.1/lib/action_view/base.rb:249:in `compile_and_render_template'' c:/progra~1/Ruby/lib/ruby/gems/1.8/gems/actionpack-1.9.1/lib/action_view/base.rb:220:in `render_template'' On 9/13/05, Jamis Buck <jamis-uHoyYlH2B+GakBO8gow8eQ@public.gmane.org> wrote:> > On Sep 13, 2005, at 11:58 AM, Anatol Pomozov wrote: > > > OK. It works. Thanks. > > > > But... How to test it?? I could not catch where I to find > > Controller instance in my NotificationsTest.. > > Just instantiate one: > > Notifications.deliver_signup(ApplicationController.new, ...) > > - Jamis > > > > > On 9/13/05, Jarkko Laine < jarkko-k1O+Gnc6WpmsTnJN9+BGXg@public.gmane.org> wrote: > > On 13.9.2005, at 18.54, Anatol Pomozov wrote: > > > >> Unfortunately it does not work for me. > >> > >> This is my model > >> > >> class Notifications < ActionMailer::Base > >> SYSTEM_EMAIL = ''Dark Throne System Email < > >> donotreply-dTlVyljHlJfz1n+OaKNE4w@public.gmane.org>'' > >> > >> helper ActionView::Helpers::UrlHelper > >> > >> def signup(user, confirm_link, remove_link) > >> @subject = ''Thank you for registering'' > >> @body[''user''] = user > >> @recipients = user.email > >> @from = SYSTEM_EMAIL > >> end > >> end > >> > >> This is mailer view > >> > >> Dear, <%= @ user.firstname %> <%= @user.lastname %> > >> Thank you for registering an account. To confirm your account, > >> click the link below: > >> <%= url_for(:action=>''confirm_authorization'',:id=>@user.auth_code) %> > >> If you have not signed up for an account or believe this email is > >> incorrect, click the link below: > >> <%= url_for(:action=>''remove_authorization'',:id=>@user.auth_code) %> > >> > >> And I still got a error > >> > >> What''s wrong with my code?? > > > > You''re confusing two approaches. If you provide the two links as > > parameters, you should use them directly in the template (see my > > previous post for how). If you want to use the approach Jamis > > described (and use the helper in your mail template), you need to > > give the controller as a parameter to the action. > > > > So not: > > def signup(user, confirm_link, remove_link) > > > > ...but: > > def signup(controller, user) > > > > This whole process is described in the wiki page Jamis referred to. > > > > //jarkko > > > > > >> > >> > >> > >> On 9/13/05, Jamis Buck <jamis-uHoyYlH2B+GakBO8gow8eQ@public.gmane.org > wrote: On Sep 13, > >> 2005, at 4:45 AM, Anatol Pomozov wrote: > >> > >> > Thanks everyone for responses. > >> > Seems that create url in controller is only solution. Anyway I > >> > would prefer to have some of ActionPack helpers accessible in > >> > ActiveTemplate view just like plain in *.rthml view. I think > >> > generating application url in mail is a widely used and I would > >> > like to see this operation simpler. > >> > Forgive me if i misunderstood rails zen and if it is "right" when > >> > ActiveMailer view nothing knows about HTTP request and controllers. > >> > >> Please see: > >> > >> http://wiki.rubyonrails.com/rails/show/ > >> HowtoUseUrlHelpersWithActionMailer > >> > >> for more about why this can''t "just work", and how to easily make it > >> work. > >> > >> - Jamis > >> > >> > > >> > > >> > On 9/13/05, Jarkko Laine < jarkko-k1O+Gnc6WpmsTnJN9+BGXg@public.gmane.org > wrote: > >> > On 13.9.2005, at 13.02, Dee Zsombor wrote: > >> > > >> > > I think that as ActionMailer templates are not evaluated in > >> context > >> > > of a > >> > > controller, url_for and link_to will not work regardeless of > >> syntax. > >> > > >> > Ah, bummer, you''re right. I also used parameters for this: > >> > > >> > class LoginMailer < ActionMailer::Base > >> > > >> > def register_request(recipients, client, approve_url) > >> > .. > >> > end > >> > end > >> > > >> > And in the template: > >> > <%= @approve_url %> > >> > > >> > Then I can call the delivery method in a controller like this: > >> > @approve_url = url_for :controller => "admin", :action > >> > => "approve_user", :id => @client.id <http://client.id> > >> > LoginMailer.deliver_register_request(@recipients, > >> > @client, @approve_url) > >> > > >> > hth, > >> > //jarkko > >> > > >> > > >> > > > >> > > I got around this problem by generating the sent URL in the > >> > > controller via > >> > > url_for. Then pass it to ActionMailer as string. I''m > >> interested in a > >> > > better solution. > >> > > >> > -- > >> > anatol > >> > _______________________________________________ > >> > Rails mailing list > >> > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > >> > http://lists.rubyonrails.org/mailman/listinfo/rails > >> > > >> > >> > >> > >> > >> -- > >> anatol > >> _______________________________________________ > >> Rails mailing list > >> Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > >> http://lists.rubyonrails.org/mailman/listinfo/rails > >> > > > > > > > > > > > > -- > > anatol > > _______________________________________________ > > Rails mailing list > > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > >-- anatol _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
hi Guys, I think I fixed this with the patch I just submitted: http://dev.rubyonrails.org/ticket/3517 CHEERS> SAM Anatol Pomozov wrote:> I got an error. > > 1) Error: > test_signup(NotificationsTest): > ActionView::TemplateError: undefined method `rewrite'' for nil:NilClass > On line #5 of /app/views/notifications/signup.rhtml > > 2: > 3: Thank you for registering an account with. To confirm your > account, click the link below: > 4: > 5: <%= > url_for(:action=>''confirm_authorization'',:id=>@user.auth_code) %> > 6: > 7: If you have not signed up for an account with or believe this > email is incorrect, click the link below: > 8: > > > c:/progra~1/Ruby/lib/ruby/gems/1.8/gems/activesupport-1.1.1/lib/active_support/whiny_nil.rb:30:in > `method_missing'' > > c:/progra~1/Ruby/lib/ruby/gems/1.8/gems/actionpack-1.9.1/lib/action_controller/base.rb:440:in > `url_for'' > > c:/progra~1/Ruby/lib/ruby/gems/1.8/gems/actionpack-1.9.1/lib/action_view/helpers/url_helper.rb:18:in > `send'' > > c:/progra~1/Ruby/lib/ruby/gems/1.8/gems/actionpack-1.9.1/lib/action_view/helpers/url_helper.rb:18:in > `url_for'' > > D:/work/darkthrone/darkthrone-ruby/trunk/app/views/notifications/signup.rhtml:5:in > `__compiled_method_2'' > > c:/progra~1/Ruby/lib/ruby/gems/1.8/gems/actionpack-1.9.1/lib/action_view/base.rb:249:in > `send'' > > c:/progra~1/Ruby/lib/ruby/gems/1.8/gems/actionpack-1.9.1/lib/action_view/base.rb:249:in > `compile_and_render_template'' > > c:/progra~1/Ruby/lib/ruby/gems/1.8/gems/actionpack-1.9.1/lib/action_view/base.rb:220:in > `render_template'' > > > > On 9/13/05, *Jamis Buck* <jamis@37signals.com > <mailto:jamis@37signals.com>> wrote: > > On Sep 13, 2005, at 11:58 AM, Anatol Pomozov wrote: > > > OK. It works. Thanks. > > > > But... How to test it?? I could not catch where I to find > > Controller instance in my NotificationsTest.. > > Just instantiate one: > > Notifications.deliver_signup(ApplicationController.new, ...) > > - Jamis > > > > > On 9/13/05, Jarkko Laine < jarkko@jlaine.net > <mailto:jarkko@jlaine.net>> wrote: > > On 13.9.2005, at 18.54, Anatol Pomozov wrote: > > > >> Unfortunately it does not work for me. > >> > >> This is my model > >> > >> class Notifications < ActionMailer::Base > >> SYSTEM_EMAIL = ''Dark Throne System Email < > >> donotreply@darkthrone.com <mailto:donotreply@darkthrone.com>>'' > >> > >> helper ActionView::Helpers::UrlHelper > >> > >> def signup(user, confirm_link, remove_link) > >> @subject = ''Thank you for registering'' > >> @body[''user''] = user > >> @recipients = user.email > >> @from = SYSTEM_EMAIL > >> end > >> end > >> > >> This is mailer view > >> > >> Dear, <%= @ user.firstname %> <%= @user.lastname %> > >> Thank you for registering an account. To confirm your account, > >> click the link below: > >> <%> url_for(:action=>''confirm_authorization'',:id=>@user.auth_code) %> > >> If you have not signed up for an account or believe this email is > >> incorrect, click the link below: > >> <%> url_for(:action=>''remove_authorization'',:id=>@user.auth_code) %> > >> > >> And I still got a error > >> > >> What''s wrong with my code?? > > > > You''re confusing two approaches. If you provide the two links as > > parameters, you should use them directly in the template (see my > > previous post for how). If you want to use the approach Jamis > > described (and use the helper in your mail template), you need to > > give the controller as a parameter to the action. > > > > So not: > > def signup(user, confirm_link, remove_link) > > > > ...but: > > def signup(controller, user) > > > > This whole process is described in the wiki page Jamis referred to. > > > > //jarkko > > > > > >> > >> > >> > >> On 9/13/05, Jamis Buck <jamis@37signals.com > <mailto:jamis@37signals.com> > wrote: On Sep 13, > >> 2005, at 4:45 AM, Anatol Pomozov wrote: > >> > >> > Thanks everyone for responses. > >> > Seems that create url in controller is only solution. Anyway I > >> > would prefer to have some of ActionPack helpers accessible in > >> > ActiveTemplate view just like plain in *.rthml view. I think > >> > generating application url in mail is a widely used and I would > >> > like to see this operation simpler. > >> > Forgive me if i misunderstood rails zen and if it is "right" > when > >> > ActiveMailer view nothing knows about HTTP request and > controllers. > >> > >> Please see: > >> > >> http://wiki.rubyonrails.com/rails/show/ > <http://wiki.rubyonrails.com/rails/show/> > >> HowtoUseUrlHelpersWithActionMailer > >> > >> for more about why this can''t "just work", and how to easily > make it > >> work. > >> > >> - Jamis > >> > >> > > >> > > >> > On 9/13/05, Jarkko Laine < jarkko@jlaine.net > <mailto:jarkko@jlaine.net> > wrote: > >> > On 13.9.2005, at 13.02, Dee Zsombor wrote: > >> > > >> > > I think that as ActionMailer templates are not evaluated in > >> context > >> > > of a > >> > > controller, url_for and link_to will not work regardeless of > >> syntax. > >> > > >> > Ah, bummer, you''re right. I also used parameters for this: > >> > > >> > class LoginMailer < ActionMailer::Base > >> > > >> > def register_request(recipients, client, approve_url) > >> > .. > >> > end > >> > end > >> > > >> > And in the template: > >> > <%= @approve_url %> > >> > > >> > Then I can call the delivery method in a controller like this: > >> > @approve_url = url_for :controller => "admin", > :action > >> > => "approve_user", :id => @client.id <http://client.id> > >> > LoginMailer.deliver_register_request (@recipients, > >> > @client, @approve_url) > >> > > >> > hth, > >> > //jarkko > >> > > >> > > >> > > > >> > > I got around this problem by generating the sent URL in the > >> > > controller via > >> > > url_for. Then pass it to ActionMailer as string. I''m > >> interested in a > >> > > better solution. > >> > > >> > -- > >> > anatol > >> > _______________________________________________ > >> > Rails mailing list > >> > Rails@lists.rubyonrails.org <mailto:Rails@lists.rubyonrails.org> > >> > http://lists.rubyonrails.org/mailman/listinfo/rails > >> > > >> > >> > >> > >> > >> -- > >> anatol > >> _______________________________________________ > >> Rails mailing list > >> Rails@lists.rubyonrails.org <mailto:Rails@lists.rubyonrails.org> > >> http://lists.rubyonrails.org/mailman/listinfo/rails > >> > > > > > > > > > > > > -- > > anatol > > _______________________________________________ > > Rails mailing list > > Rails@lists.rubyonrails.org <mailto:Rails@lists.rubyonrails.org> > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > > > > > -- > anatol > >------------------------------------------------------------------------ > >_______________________________________________ >Rails mailing list >Rails@lists.rubyonrails.org >http://lists.rubyonrails.org/mailman/listinfo/rails > >