Re: [Rails] One form, multiple models, custom validation
On 23/12/10 10:32, Serafino Picozzi wrote:
> Hi everyone,
>
> I hope someone can help me solve this problem.
> I have a model called Project with :has_many => :tasks. In the new
> Project form i allow the creation of 1 to n tasks on the fly thanks to
> accepts_nested_attributes_for, where the task model has some validations
> that block the creation of the new project if the required fields are
> not correct.
>
> This works just fine as it is supposed to work, but here's the problem:
>
> At least one task needs to have some fields not empty, otherwise the
> project should not be created. It can be any of the tasks but it's
> imperative that at least one of them has those attributes, for the other
> tasks these attributes are not required.
> Is there a way of doing that without strange hacks?
>
> Thanks in advance for your help
>
Hi Serafino,
I am assuming that you are using Javascript. If that is the case, then
you can find the solution here
http://stackoverflow.com/questions/1704142/unobtrusive-dynamic-form-fields-in-rails-with-jquery
All the best,
Fidel.
--
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@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home