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(''<br />'')
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!
-- 
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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
Dan Manges
2007-Feb-06  20:32 UTC
Re: Help w/ errors.add_to_base between controller and model
On Feb 6, 12:23 pm, Clem Rock <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> 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 Manges --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Clem Rock
2007-Feb-06  21:34 UTC
Re: Help w/ errors.add_to_base between controller and model
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 Manges wrote:> On Feb 6, 12:23 pm, Clem Rock <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> > 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 Manges-- 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Clem Rock
2007-Feb-06  21:45 UTC
Re: Help w/ errors.add_to_base between controller and model
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 
clemrock-PkbjNfxxIARBDgjK7y7TUQ@public.gmane.org
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:in `bulk''
#{RAILS_ROOT}/app/controllers/invite_controller.rb:30:in `bulk''
Clem Rock 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 Manges wrote:
>> On Feb 6, 12:23 pm, Clem Rock
<rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>
>> 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 Manges
-- 
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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
Dan Manges
2007-Feb-06  23:33 UTC
Re: Help w/ errors.add_to_base between controller and model
On Feb 6, 4:34 pm, Clem Rock <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> 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 Manges --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Clem Rock
2007-Feb-08  06:14 UTC
Re: Help w/ errors.add_to_base between controller and model
Dan - here''s a link to the code in pastie http://pastie.caboo.se/38769 Thanks for your help big time -- 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---