’SOLVED'' I totally forgot to look at the ''old''
acts_as_a_list , now a
plugin ...!
On Mar 22, 7:32 pm, Erwin <yves_duf...-ee4meeAH724@public.gmane.org>
wrote:> I am trying to write a validation for a specific use case
> when an admin wants to change a project payment terms, I display a
> form listing the existing payment terms for this project in sequence
> 1 rate: 30% label ..
> 2 rate: 30% label ..
> 3 rate: 40% label ..
>
> An admin should be able to add a new payment_term ( add_association
> in nested form) or delete an existing one..
> but also re-order the sequence.... i.e change 1=> 3 and 3 => 1
> I am trying to set up a validation, so a seq number cannot be created
> twice , but it doesn''t work ...
>
> Project
> has_many :payment_terms
> accepts_nested_attributes_for :payment_terms, :reject_if
> => :all_blank, :allow_destroy => true
> attr_accessible :payment_terms_attributes
>
> PaymentTerm
> belongs_to :project
> attr_accessible :seq, :rate, ....
>
> validates :term_seq, :numericality => { :greater_or_equal_to => 0 }
> validates :rate, :numericality => { :greater_than =>
> 0.0, :less_than_or_equal_to => 100.0 }
>
> obviously a :seq attribute should be unique within the scope of the
> project, so I tried :
> validates :seq, :uniqueness => { :scope => :project_id, :message
=>
> "Seq.?" }
>
> BUT, updating the payment terms
> id: 23 :seq 1 rate: 30%
> id: 24 :seq 2 rate: 30%
> id: 25 :seq 3 rate: 40%
>
> to ( as an example)
> id: 23 :seq 2 rate: 30% <= first record to update
> id: 24 :seq 3 rate: 30%
> id: 25 :seq 1 rate: 40%
>
> doesn''t work at all.... updating id: 23 raises a validation
error
> as :seq 2 is already existing in record :24
> so scoping is not the solution, is this a bad design I could change ?
--
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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
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.