Help w/ errors.add_to_base between controller and model

Help w/ errors.add_to_base between controller and model

Hello,

I'm having trouble in routing some errors between model and

controller. The errors produced in the controller
(invite_controller.rb) are collected and spit out nicely in a
flash[:validate] method as such:

if errors.size > 0
flash[:validation] = errors.join(’
’)
end

Errors produced in the model (invite.rb) are displayed w/in a giant page
failure explosion and are not routed into the flash[:validate] method.

The code for the the method is as follows:

self.errors.add_to_base(“an invitation has already been sent to
#{email}”)

Is there a way where I can route the model errors to the
flash[:validate] method as I am in the controller?

Thanks for your help!

On Feb 6, 12:23 pm, Clem R. [email protected]
wrote:

Is there a way where I can route the model errors to the
flash[:validate] method as I am in the controller?

Will something like this work:

if model.save
flash[:success] = “model successfully saved”
else
flash[:validate] = model.errors.full_messages.join("\n")
end

Dan M.

Hello,

I tried using the flash[:validate] method in the model and it shows
the “method not found” error.

What exactly does the model.save method do?

Dan M. wrote:

On Feb 6, 12:23 pm, Clem R. [email protected]
wrote:

Is there a way where I can route the model errors to the
flash[:validate] method as I am in the controller?

Will something like this work:

if model.save
flash[:success] = “model successfully saved”
else
flash[:validate] = model.errors.full_messages.join("\n")
end

Dan M.

More on that- here’s the full errors that are displayed.

Official validation error from the model:
Validation failed: an invitation has already been sent to
[email protected]

And the other errors from the page failure:

/opt/local/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/validations.rb:748:in
save!' #{RAILS_ROOT}/app/controllers/invite_controller.rb:40:inbulk’
#{RAILS_ROOT}/app/controllers/invite_controller.rb:30:in `bulk’

Clem R. wrote:

Hello,

I tried using the flash[:validate] method in the model and it shows
the “method not found” error.

What exactly does the model.save method do?

Dan M. wrote:

On Feb 6, 12:23 pm, Clem R. [email protected]
wrote:

Is there a way where I can route the model errors to the
flash[:validate] method as I am in the controller?

Will something like this work:

if model.save
flash[:success] = “model successfully saved”
else
flash[:validate] = model.errors.full_messages.join("\n")
end

Dan M.

Dan - here’s a link to the code in pastie

http://pastie.caboo.se/38769

Thanks for your help big time

On Feb 6, 4:34 pm, Clem R. [email protected] wrote:

I tried using the flash[:validate] method in the model and it shows
the “method not found” error.

What exactly does the model.save method do?

Can you copy and paste your model and controller action? If it’s big
use Pastie http://pastie.caboo.se/ and post a link here.

Thanks,
Dan M.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs