Ruby on Rails Question

How do you add business logic errors to the ApplicationController instead of
in the Model? (ie. errors.add_on_empty(["title", "body"])
errors.add_on_empty(["title", "body"])) The error I want to generate is tied
to code that would be called within the ApplicationController and has
nothing to do with the Model, but I would like it to appear along with the
other errors in the View.

Thanks

Ken

kenfettig@btinet.net

This is the Ruby language mailing list. You'd get better answers by
asking on the Rails ml.

Jacob

···

On 9/8/05, Ken Fettig <kenfettig@btinet.net> wrote:

How do you add business logic errors to the ApplicationController instead of
in the Model? (ie. errors.add_on_empty(["title", "body"])
errors.add_on_empty(["title", "body"])) The error I want to generate is tied
to code that would be called within the ApplicationController and has
nothing to do with the Model, but I would like it to appear along with the
other errors in the View.

Thanks

Ken

kenfettig@btinet.net

If you have access to the model object, then you can use the attribute
accessor obj.errors to add the message.

For example,

      @user = User.new(params[:user])
      @user.errors.add(:name, 'Name cannot be left blank...')

Barry

Ken Fettig wrote:

···

How do you add business logic errors to the ApplicationController instead of
in the Model? (ie. errors.add_on_empty(["title", "body"])
errors.add_on_empty(["title", "body"])) The error I want to generate is tied
to code that would be called within the ApplicationController and has
nothing to do with the Model, but I would like it to appear along with the
other errors in the View.

Thanks

Ken

kenfettig@btinet.net

Thanks much!!!!! That worked!!!
Now is there a way to get rid of or override the default message that it
generates? ("1 error prohibited this user from being saved"). The error
that I want to display is actually an invalid login error so the default
message makes it confusing.

"Barry" <rubyrails@gmail.com> wrote in message
news:1126247082.681012.143310@g44g2000cwa.googlegroups.com...

···

If you have access to the model object, then you can use the attribute
accessor obj.errors to add the message.

For example,

     @user = User.new(params[:user])
     @user.errors.add(:name, 'Name cannot be left blank...')

Barry

Ken Fettig wrote:

How do you add business logic errors to the ApplicationController instead
of
in the Model? (ie. errors.add_on_empty(["title", "body"])
errors.add_on_empty(["title", "body"])) The error I want to generate is
tied
to code that would be called within the ApplicationController and has
nothing to do with the Model, but I would like it to appear along with
the
other errors in the View.

Thanks

Ken

kenfettig@btinet.net