Trying to create a contact form

def notifications(sent_at = Time.now)    subject params[:subject]

You're not in your controller anymore - you can't access the params
hash like that. Anything you need in your mailer needs to be passed as
an argument to it (although you could pass params hash itself if you
wanted)

Fred

Frederick Cheung wrote:

def notifications(sent_at = Time.now)    subject params[:subject]

You're not in your controller anymore - you can't access the params hash like that. Anything you need in your mailer needs to be passed as an argument to it (although you could pass params hash itself if you wanted)

Fred

so I need to do @subject = params[:subject] in the controller and then supply @subject in the model?

You can set up instance variables in your mailer model accessible
inside the view like this:

# allows access to @message and @sender_name :message => email_params[:body], :sender_name => email_params[:name]

Controller =

def send_mail    @name = params[:name]    @subject = params[:subject]    @body = params[:body]    @address = params[:address]

The controller and the mailer are different objects - you can't set
instance variables in one and expect them to appear in the other. Pass
what you need as arguments to your mailer

Fred

I'm sorry if I'm newbish on this subject and some things I understand and others I don't. I believe I have this very close to being correct:

My Mailer modle is mailer.rb

class Mailer < ActionMailer::Base

  def notifications(email_params, sent_at = Time.now)     subject email_params[:subject]     recipients 'webmaster@ncaastatpages.com'     from email_params[:address]     sent_on sent_at     body :greeting => email_params[:body], :sender_name => email_params[:name]   end

end

As you can see it has the class Mailer which is a part of ActionMailer::Base. I'm also defining the method for notifications and asking for email_params to be sent to it.

The controller for my contacts page:

  def send_mail     Mailer.deliver_notifications(params[:email])     flash[:notice] = "Email was succesfully sent."     redirect_to :action => "index"   end

Contains the method for send_mail which is making a direct call to the Mailer class and providing params[:email].

params[:email] parameters are specified from the view:

                    <% form_tag :action => "send_mail" do %>                       <tr><td>                           <%= label :email, :name, "Name" %><br />                           <%= text_field :email, :name %>                       </td></tr>                       <tr><td>                           <%= label :email, :address, "Your Email Address" %><br />                           <%= text_field :email, :address %>                       </td></tr>                       <tr><td>                           <%= label :email, :subject, "Subject" %><br />                           <%= text_field :email, :subject %>                       </td></tr>                       <tr><td>                           <%= label :email, :body, "Your Message" %><br />                           <%= text_area :email, :body, :rows => 8, :cols => 50 %>                       </td></tr>                       <tr><td>                           <%= submit_tag "Submit" %>                       </td></tr>                     <% end %>

Again, I get no errors of any sort but no mail is received. If you see something that I'm doing wrong, if you could provide a small code snippet for correction, I will understand your explanation better.

At this point it's probably down to action mailer's configuration. You mention you've setup config/mail.yml - that's not a rails thing (unless that's slipped in recently). Action mailer settings are setup in the appropriate environment file (so development.rb for the moment).

Fred

Thanks for the input Fred.

I actually removed that - it was being "potentially" used for something else down the road, so it really didn't apply here.

I've decided to take an entirely different approach with the contact form at this point. I believe the easier way to implement it, and even administrate it, would be to use a scaffold with restful and then remove the layout file. I then have everything in place. I was looking at the following video:

http://s3.amazonaws.com/lr_screencasts/learningrails-18.mov

It was a fairly good watch and I liked how they did the approach. I know there is probably a simpler way for implementing this but with a scaffold approach, it will also make testing easier.

Thanks mate - wish me luck.