On 2010-10-05, at 10:41 PM, Jim Burgess wrote:

> 
>> validate do |applicant|
>>  errors.add_to_base("Things must check out!") unless 
>> applicant.check_things
>> end
>> 
>> def before_save
>>  applicant.non_represented_field = 123456789
>> end
>> 
>> before_save will only be called if your validations pass, so 
>> non_represented_field will only be assigned to valid records.
> 
> Hi,
> 
> Thanks for the reply.
> 
> Sorry, I don't think I expressed myself very well.
> 
> When I submit the form, every value the applicant has entered is 
> validated and passed to the controller. That means that if they enter a 
> value in the email field (for example) I can access this value in the 
> controller in the params hash, regardless of whether validation failed 
> or passed.
> 
> As this 'non-represented' field is only getting set after a successful 
> validation, it is not available in the params hash until everything has 
> been filled out correctly. Before that it always shows as nil.
> 
> I would like to set this value in my model with every form submission 
> (it is a hash which is always a different value per submission) so that 
> it is always available in the params has in the controller.
> 
> I really appreciate any help.
> 

Perhaps you could post the pertinent code ? Do you have validation checks in 
the form (via javascript) or just the ones in model ?

blah = Blah.new(params[:blah])

#now you have a instance of Blah.

if blah.save
  #now you have access to the non represented field
  blah.non_represented_field
end

Another approach might be to pass this value from the new action to the create 
action through the form using a hidden field.

Luke


-- 
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-t...@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to