Hey people, does anyone know if it''s possible to access params inside the before_validation function? -- 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 -~----------~----~----~----~------~----~------~--~---
On 24 Mar 2009, at 10:17, Heinz Strunk wrote:> > Hey people, > > does anyone know if it''s possible to access params inside the > before_validation function?before_validation callbacks are instance methods of models, params is an instance method of controllers therefore you cannot call params from a before_validation callback. Fred> > -- > 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 -~----------~----~----~----~------~----~------~--~---
On Tue, Mar 24, 2009 at 5:17 AM, Heinz Strunk <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > Hey people, > > does anyone know if it''s possible to access params inside the > before_validation function?Aren''t you doing something like Foo.new( params[:foo] ) already? params is an array and responds to merge, so you can add stuff to params before passing it to the model. -- Greg Donald http://destiney.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 -~----------~----~----~----~------~----~------~--~---
Alright, thank you for the info! -- 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 -~----------~----~----~----~------~----~------~--~---
Greg Donald wrote:> On Tue, Mar 24, 2009 at 5:17 AM, Heinz Strunk > <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote: >> >> Hey people, >> >> does anyone know if it''s possible to access params inside the >> before_validation function? > > Aren''t you doing something like Foo.new( params[:foo] ) already? > > params is an array and responds to merge, so you can add stuff to > params before passing it to the model. > > > > -- > Greg Donald > http://destiney.com/I''ve got a similiar problem but need to remove two attributes I only need for validation. I have my model plus two attributes (current, required) and I want to validate these two attributes before saving. I cannot create a new instance because it says "unknown attribute current" I could do @errorcheck_current = params[:activity].delete(''current'') but then I cannot use it in the model for validation. Does anyone know how to solve that kind of problem? -- Posted via http://www.ruby-forum.com/.
Heinz Strunk wrote: [...]> I''ve got a similiar problem but need to remove two attributes I only > need for validation. > I have my model plus two attributes (current, required) and I want to > validate these two attributes before saving. I cannot create a new > instance because it says "unknown attribute current" > > I could do @errorcheck_current = params[:activity].delete(''current'') but > then I cannot use it in the model for validation. Does anyone know how > to solve that kind of problem?Delete the virtual attributes *after* validation, perchance? The after_validation_* callbacks might help... Best, -- Marnen Laibow-Koser http://www.marnen.org marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.org -- Posted via http://www.ruby-forum.com/.
On Wed, Oct 7, 2009 at 6:39 AM, Heinz Strunk <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> I''ve got a similiar problem but need to remove two attributes I only > need for validation. > I have my model plus two attributes (current, required) and I want to > validate these two attributes before saving. I cannot create a new > instance because it says "unknown attribute current"Sounds like you need to add attr_accessor entries. attr_accessor :current, :required -- Greg Donald http://destiney.com/