Hi, I have an actionmailer script that happily processes an inbox. It is called via script & reads emails & grabs the attachments for further processing I want to be able to access a method [process_attachment] in app/controllers/application.rb, but the mailman routine does not appear to be able to access it. I''ve tried both including environment.rb & app/controllers/application.rb but still get the error - undefined method ''process_attachment'' Is there anyway to do this, or do I have to move the logic somewhere else..?? -------------------------------------------- mailman.rb -------------------------------------------- require File.dirname(__FILE__) + ''/../../config/environment.rb'' require File.dirname(__FILE__) + ''/../../app/controllers/application.rb'' class Inbound < ActiveRecord::Base end class Mailman < ActionMailer::Base def receive(email) email.attachments.each do |attachment| inbound = Inbound.new inbound.attachment = attachment process_attachment(inbound) end end end -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Matt Stone wrote:> Hi, > > I have an actionmailer script that happily processes an inbox. It is > called via script & reads emails & grabs the attachments for further > processing > > I want to be able to access a method [process_attachment] in > app/controllers/application.rb, but the mailman routine does not appear > to be able to access it. I''ve tried both including environment.rb & > app/controllers/application.rb but still get the error - undefined > method ''process_attachment'' > > Is there anyway to do this, or do I have to move the logic somewhere > else..?? > > -------------------------------------------- > mailman.rb > -------------------------------------------- > > require File.dirname(__FILE__) + ''/../../config/environment.rb'' > require File.dirname(__FILE__) + ''/../../app/controllers/application.rb'' > > class Inbound < ActiveRecord::Base > end > > class Mailman < ActionMailer::Base > > def receive(email) > email.attachments.each do |attachment| > inbound = Inbound.new > inbound.attachment = attachment > process_attachment(inbound) > end > end > end > >Hey I''m not sure if this is the best method, its probably not even a good method :] but it''s something you could try in the meantime :) extract the method into a separate file into your /lib directory, aka. /lib/my_truly_global_methods.rb Then require this file in either your environment.rb, or (less blasphemously) in your mailer class. Doesn''t feel very elegant, I know, but I''m not sure if something like helper_method exists for mailers... Hope this helps... Cheery-o Gustav Paul gustav-PUm+PnBUKx7YkQIYctQFYw@public.gmane.org --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
simon.martinelli-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2006-Nov-15 14:25 UTC
Re: ActionMailer & controller
Hi Matt, Dumb question: Where is the methode process_attachment currently defined? Regards, Simon --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
simon.martinelli-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org wrote:> Hi Matt, > > Dumb question: > Where is the methode process_attachment currently defined? > > Regards, SimonSimon, Thanks for your response, I really appreciate it. process_attachement is defined in app/controller/application.rb. It also processes uploaded files. I want to have the same logic process the files uploaded via a browser, & files sent as attachments. I''m really confused as to how is the best way to achieve this. rgds, - matt. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
simon.martinelli-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2006-Nov-15 19:16 UTC
Re: ActionMailer & controller
Ah ok. Now I understand. Your problem is, that ApplicationController is the parent class of all Controllers in a Ruby on Rails Application. But you extend ActionMailer and ActionMailer doesn''t extends ApplicationController. You could do the following class Mailman < ActionMailer::Base def receive(email) application = ApplicationController.new email.attachments.each do |attachment| inbound = Inbound.new inbound.attachment = attachment application.process_attachment(inbound) end end end I''m not sure if this is an elegant solution but it should work. Otherwise put process_attachement in any class and you can instantiate this instead of ApplicationController. Cheers, Simon --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Simon, Thanks for that - works perfectly. The explanation was great, I know understand why it works perfectly. rgds, - matt. simon.martinelli-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org wrote:> Ah ok. Now I understand. > > Your problem is, that ApplicationController is the parent class of all > Controllers in a Ruby on Rails Application. > But you extend ActionMailer and ActionMailer doesn''t extends > ApplicationController. > > You could do the following > > class Mailman < ActionMailer::Base > > def receive(email) > application = ApplicationController.new > email.attachments.each do |attachment| > inbound = Inbound.new > inbound.attachment = attachment > application.process_attachment(inbound) > end > end > end > > I''m not sure if this is an elegant solution but it should work. > Otherwise put process_attachement in any class and you can instantiate > this instead of ApplicationController. > > Cheers, Simon-- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---