Topic: I get error

I added the following code to config/environments/development.rb
config.action_mailer.delivery_method = :smtp
ActionMailer::Base.server_settings = {
:address => "sriserver3",
:port => 25

and get an error while starting the server. The error is as follows:

C:\>ruby "c:\program files\apache group\apache2\htdocs\GoHuman\script\server"
=> Booting WEBrick...
es.rb:477:in `const_missing': uninitialized constant Rails::Initializer::ActionM
ailer (NameError)
        from c:/program files/apache group/apache2/htdocs/GoHuman/script/../conf
ig/../config/environments/development.rb:24:in `load_environment'
        from c:/ruby/lib/ruby/gems/1.8/gems/rails-1.2.3/lib/initializer.rb:204:i
n `load_environment'
        from c:/ruby/lib/ruby/gems/1.8/gems/rails-1.2.3/lib/initializer.rb:201:i
n `silence_warnings'
        from c:/ruby/lib/ruby/gems/1.8/gems/rails-1.2.3/lib/initializer.rb:201:i
n `load_environment'
        from c:/ruby/lib/ruby/gems/1.8/gems/rails-1.2.3/lib/initializer.rb:85:in
        from c:/ruby/lib/ruby/gems/1.8/gems/rails-1.2.3/lib/initializer.rb:43:in
        from c:/ruby/lib/ruby/gems/1.8/gems/rails-1.2.3/lib/initializer.rb:43:in
        from c:/program files/apache group/apache2/htdocs/GoHuman/script/../conf
         ... 11 levels...
        from c:/ruby/lib/ruby/gems/1.8/gems/rails-1.2.3/lib/commands/server.rb:3
        from c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `ge
        from c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `re
        from c:/program files/apache group/apache2/htdocs/GoHuman/script/server:

Iam not sure what is wrong. can anyone help me in this regard.


Re: I get error


I some how got rid of this error. Thanks. But when I ran ny program I get an error "You have a nil object when you didn't expect it!
The error occurred while evaluating nil.email_address_with_name" The method is as follows:

def signup_notification(recipient)
    recipients recipient.email_address_with_name
    from       ""
    subject    "New account information"
    body       :account => recipient

and my layout page has
Hi <%= %>,
  Thanks for joining our service! Please check back often.

my controller code looks like this:

def create
    @register =[:register])
      flash[:notice] = 'New User Has Been Successfully Created.'
      redirect_to :action => 'list'
      render :action => 'new'

but when I give the details statically say

def signup_notification(recipient)
    recipients ""
     from       ""
     subject    "New account information"
     body       "Hai"

I get the mail but the layout page details is missing.

Where Am I wrong. Can anyone help me in this regard

Thanks a lot!!!

Re: I get error

I do not see where you are creating the instance of the @account object in your controller which could be the problem.

The way I set my program up is as follows.
Step one: in the SubmitA method of page A, the mail piece is created.
Step two: in the SubmitA method, there is a redirect call to the view B
Step three: in the ViewB controller method that populates viewB, there is an instance of the object to be displayed (in your case @account)

Hopefully this will help you sort this out.  If not, please reply and I can show you my code (I refrained because there is a lot of stuff going on with it and in the end it may be more confusing than helpful).

Re: I get error

Thanks a lot. I made the necessary changes and I still get the same error. I dont know how to pass the email id given by the user. When I pass it statically I receive the mail . when I do so dynamically I get the error. Please help me.


Re: I get error

The way I am passing parameters is like this (this may not be the best form, but it worked for me):

in my controller, I create a function to create the mail peice that is called in my create and update methods.

These are the lines that dynamically pass the information in the controller:
1. @email =
2. @name = @applicanth.fname + " " + @applicanth.lname
3. Notifications::deliver_confirmation(@email, @name)

line 1 then gets the email address from the user table.
line 2 pulls the fname and lname from the applicanth table and concatenates them into the users name with a space in between them.
line 3 passes these parameters to the mailer.

in my model Notifications.rb

1.  def confirmation(to, name, sent_at =
2.    #this function sets variable values for outgoing emails
3.    @subject    = 'Your application has been completed and received'
4.    @body['name']=name
5.    @recipients = to
6.    @from       = 'from@email.address
7.    @sent_on    = sent_at
8.    @headers    = {}
9.  end

Here, @recipients receives the @email from the controller and @body['name'] gets the user's name

and in the view
1. Dear <%= @name %>

this line pulls the @name into the body of the email from the @body['name'] in the model

Let me know if any of this is and I will try to explain it better.

Re: I get error

Thanks a lot and lot more david. I got it working. can you help me in one more issue. I need to validate for correct email address and check whethere the password and the retype password matches. How to validate both the fields.


Re: I get error

I can jump in with the last question.

The best validation for email that I've found I've included below.  Also, the way you verify that the password was typed twice is that you include a field in the model (usually 'password') and create two fields in your html: 'password' and 'password_confirmation'.  The second never gets saved to the database - only tested for validation.

Here's how the model looks:

class User < ActiveRecord::Base
  validates_format_of :email, :with => /^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i
  validates_confirmation_of :password

Re: I get error

Thanks a lot. The email is getting validated but iam unable to validate the password and retypr password. How to validate the password and retype password. They both should be same.

My code is as follows:
class Register < ActiveRecord::Base
validates_confirmation_of :password
validates_length_of :password, :within => 5..40

layout page:
<label for="register_password">Password:</label>
<%= password_field 'register', 'password',{ :class => "styled" }   %><br/>
<label for="register_password">Retype Password:</label>
<%= password_field 'register', '',{ :class => "styled" }   %><br/>

What's wrong in this code.


Re: I get error

You are missing the name on your password_confirmation field, change your code to look like this and things should be peachy:

<label for="register_password">Password:</label>
<%= password_field 'register', 'password',{ :class => "styled" } %><br/>
<label for="register_password_confirmation">Retype Password:</label>
<%= password_field 'register', 'password_confirmation, { :class => "styled" } %><br/>

"An egoless acceptance of stuckness is a key to an understanding of all Quality, in mechanical work as in other endeavors."
Zen and the Art of Motorcycle Maintenance