Hey people,
does anyone know if it’s possible to access params inside the
before_validation function?
Hey people,
does anyone know if it’s possible to access params inside the
before_validation function?
On 24 Mar 2009, at 10:17, Heinz S. 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
On Tue, Mar 24, 2009 at 5:17 AM, Heinz S.
[email protected] 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 D.
http://destiney.com/
Alright, thank you for the info!
Greg D. wrote:
On Tue, Mar 24, 2009 at 5:17 AM, Heinz S.
[email protected] 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 D.
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?
Heinz S. 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…
Marnen Laibow-Koser
http://www.marnen.org
[email protected]
Greg D. wrote:
…
attr_accessor :current, :required
–
Greg D.
http://destiney.com/
Yep, that’s what I needed. Thanks to both of you!
On Wed, Oct 7, 2009 at 6:39 AM, Heinz S.
[email protected] 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 D.
http://destiney.com/
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.
Sponsor our Newsletter | Privacy Policy | Terms of Service | Remote Ruby Jobs