I need help with my ActiveRecord model. I have context-based validations (incorrectly) using the built-in context options to validate:
validates :foo, :on => :bar, :presence => true
model = Model.new
model.foo = nil
model.valid?
model.save
model.valid?(:bar)
model.save(:context => :bar)
But using my model in accepts_nested_attributes_for :modeland the call parent.savefails (confirmation is called and returns false), any suggestions or solutions?
Still no answer? To learn more about my problem: I have a model called Formthat has many Fields. Users should see validation errors for submit, but the form should be saved anyway (with errors and without errors). There are various types of Fields, each with global checks (to ensure database consistency) and its own specific user checks (to check user input). So mine Fieldlooks like this:
validates_associated :form, :on => :global
...
def validate
validations.each do |validation|
validation.new(:on => :specific).validate(self)
end
end
In my controller:
form.attributes = params[:form]
form.save!(:global)
form.save(:specific)
Is something like this possible in Rails using inline functions? By the way, this is not my actual code, which is rather complicated. But I hope you guys come up with.