I am trying to send an email using ActionMailer. I am having problems identifying the recipient in email.controller. I want it to be the owner of the current story. It won''t accept @story.user because I don''t know how to make a relationship between the story model and the email model. Trouble is user_mailer won''t accept belongs_to. Can anybody help? Attachments: http://www.ruby-forum.com/attachment/4820/email_controller.rb -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 28 June 2010 10:22, Neil Bye <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> I am trying to send an email using ActionMailer. I am having problems > identifying the recipient in email.controller. I want it to be the owner > of the current story. > It won''t accept @story.user because I don''t know how to make a > relationship between the story model and the email model. Trouble is > user_mailer won''t accept belongs_to. Can anybody help?:recipient => @story.user.email_address -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Michael Pavling wrote:> > :recipient => @story.user.email_addressThat gives undefined method `user'' for nil:NilClass -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 28 June 2010 11:37, Neil Bye <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Michael Pavling wrote: > >> >> :recipient => @story.user.email_address > > That gives undefined method `user'' for nil:NilClassWell then the "It won''t accept @story.user because I don''t know how to make a relationship between the story model and the email model" would''ve returned that error too! If you have a Story object somewhere, and the story instance has a user, and that user has an email address, you can pass it into your ActionMailer method as a parameter (or, as it looks like you''re doing, a hash value). You can then set that passed-in email address as the "recipients" for the email. -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Michael Pavling wrote:> On 28 June 2010 11:37, Neil Bye <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote: >> Michael Pavling wrote: >> >>> >>> :recipient => @story.user.email_address >> >> That gives undefined method `user'' for nil:NilClass >> If you have a Story object somewhere, and the story instance has a > user, and that user has an email address, you can pass it into your > ActionMailer method as a parameter (or, as it looks like you''re doing, > a hash value). You can then set that passed-in email address as the > "recipients" for the email.How would I send it as a parameter then if it won''t accept my hash?. Problem is that it won''t recognise the Story object. Doesn''t it need to be related? -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 28 June 2010 15:18, Neil Bye <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Problem is that it won''t recognise the Story object.What Story object? In your controller code you don''t have one. You use a story key in the params hash, but you haven''t populated anything from the database. Is the email address in the params hash too?! Only you know where your data is.> Doesn''t it need to be related?To what? And what for? You''re interesting in an email address of a person assigned to a story. The UserMailer couldn''t care less about the relationships - it just wants an email address. If you know the story''s ID, load it (story = Story.find(story_id_from_params_or_somewhere_else)); then you can call story.user.email_address_field_name -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Michael Pavling wrote:> On 28 June 2010 15:18, Neil Bye <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote: >> Problem is that it won''t recognise the Story object. > > What Story object? In your controller code you don''t have one. You use > a story key in the params hash, but you haven''t populated anything > from the database. Is the email address in the params hash too?! > Only you know where your data is. > >> Doesn''t it need to be related? > To what? And what for? > You''re interesting in an email address of a person assigned to a > story. The UserMailer couldn''t care less about the relationships - it > just wants an email address. If you know the story''s ID, load it > (story = Story.find(story_id_from_params_or_somewhere_else)); then you > can call story.user.email_address_field_nameHow do I tell it to find the current page? -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.