Hello! I have made a common class and put it to the /lib folder of my Rails application. Now I have some problems with access to: 1. Mailers Call to SupportMailer.send_activation_email gives an error: NoMethodError (undefined method `send_activation_email'' for SupportMailer:Class): Ok, I have changed my SupportMailer class - give a prefix to the function function send_activation_email -> function self.send_activation_email But in this case the Mailer doesn''t see other models and gives an error: NoMethodError (You have a nil object when you didn''t expect it! You might have expected an instance of ActiveRecord::Base. The error occurred while evaluating nil.[]=): /app/models/support_mailer.rb:14:in `send_activation_email'' How can I access mailers? 2. Functions from application.rb I have added a function (send_sms) to the ApplicationController, but how can I access it from common class in /lib folder? I have tried: send_sms ApplicationController::send_sms But in both cases I have got NoMethodError How can I access this global function? I''m lost in all the dependencies and don''t know where to place global functions and classes and how to connect from them to another parts of the application.... --~--~---------~--~----~------------~-------~--~----~ 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 17 Dec 2008, at 17:17, Konstantin wrote:> > Hello! > > I have made a common class and put it to the /lib folder of my Rails > application. > Now I have some problems with access to: > > 1. Mailers > Call to SupportMailer.send_activation_email gives an error: > NoMethodError (undefined method `send_activation_email'' for > SupportMailer:Class): > > Ok, I have changed my SupportMailer class - give a prefix to the > function > function send_activation_email -> function self.send_activation_email > But in this case the Mailer doesn''t see other models and gives an > error: > NoMethodError (You have a nil object when you didn''t expect it! > You might have expected an instance of ActiveRecord::Base. > The error occurred while evaluating nil.[]=): > /app/models/support_mailer.rb:14:in `send_activation_email'' >That''s not how mailers work. Typically your mailer method would be called activation_email (and it must be an instance method - not a class method) Rails then magically lets you do SupportMailer.deliver_activation_email / SupportMailer.create_activation_email> How can I access mailers? > > 2. Functions from application.rb > I have added a function (send_sms) to the ApplicationController, but > how can I access it from common class in /lib folder? > I have tried: > send_sms > ApplicationController::send_sms > But in both cases I have got NoMethodError > > How can I access this global function?It''s not a global function. It''s an instance method added to all controllers> > > I''m lost in all the dependencies and don''t know where to place global > functions and classes and how to connect from them to another parts of > the application....in foo.rb class Foo def self.some_function end end call Foo.some_function anywhere you want (you could of course add the method to a more appropriate model class if there is one) Fred> > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
> It''s not a global function. It''s an instance method added to all > controllersOk, but I want to render a template in this function. How can I do that if I put it outside the controller (for example, into a separate class in a /lib folder)? Other answers are really helpful, thank you :) Actually I still cannot force my Mailer to work, it reports about "undefined method `activation_email''", although this method exists and is an instance (not class) method.... --~--~---------~--~----~------------~-------~--~----~ 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 Dec 17, 9:37 pm, Konstantin <rasf...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > It''s not a global function. It''s an instance method added to all > > controllers > > Ok, but I want to render a template in this function. > How can I do that if I put it outside the controller (for example, > into a separate class in a /lib folder)? > > Other answers are really helpful, thank you :) > Actually I still cannot force my Mailer to work, it reports about > "undefined method `activation_email''", although this method exists and > is an instance (not class) method....What are you doing to try and send an email. It should be SupportMailer.deliver_activation_email. Fred --~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---