Hi Ignacio,

yes the scope issue is fixed. Thanks!

Now I found a second thing around the reordering, which could be mentioned 
in the guide:

If you intruduce a uniquness check like this

> validates :position, numericality: true, :uniqueness => {:scope => 
> :property_group_id}

so checking the order in the scope of the parent instance, you get a 
validation error on reorderung, that this position is already taken. 

Started POST "/admin/properties/reorder" for 127.0.0.1 at 2014-01-06 
>> 10:34:29 +0100
>
> Processing by Admin::PropertiesController#reorder as JS
>
>   Parameters: {"render"=>"none", 
>> "authenticity_token"=>"cNmtsEo+hhQLGy5nqw4AYRRFWBpGJzU3ReFOQ0ss83A=", 
>> "property_ordering"=>["82073", "82072"]}
>
>   User Load (0.1ms)  SELECT `users`.* FROM `users` WHERE `users`.`id` = 
>> 664 LIMIT 1
>
>   Property Load (0.3ms)  SELECT `properties`.* FROM `properties` WHERE 
>> `properties`.`id` = 82073 LIMIT 1
>
>    (0.1ms)  BEGIN
>
>   Property Exists (0.3ms)  SELECT 1 AS one FROM `properties` WHERE 
>> (`properties`.`position` = BINARY 1 AND `properties`.`id` != 82073 AND 
>> `properties`.`property_group_id` = 20567) LIMIT 1
>
>   PropertyGroup Load (0.3ms)  SELECT `property_groups`.* FROM 
>> `property_groups` WHERE `property_groups`.`id` = 20567 ORDER BY 
>> property_groups.position ASC LIMIT 1
>
>    (0.1ms)  ROLLBACK
>
> Completed 422 Unprocessable Entity in 17ms
>
>
>> ActiveRecord::RecordInvalid - Gültigkeitsprüfung ist fehlgeschlagen: 
>> *Reihung 
>> ist bereits vergeben*:
>
>   activerecord (4.0.2) lib/active_record/validations.rb:57:in `save!'
>
>   activerecord (4.0.2) lib/active_record/attribute_methods/dirty.rb:41:in 
>> `save!'
>
>   activerecord (4.0.2) lib/active_record/transactions.rb:275:in `block in 
>> save!'
>
>
>  
The validation is done against the position value in the database and not 
between the element of the parameters sent.
So in short: don't validare uniqueness, if you want to reorder.
(Even in the edit form you had to enter a new set of position integers, so 
this has nothing to do with the ajax part itself, it is just how Rails 
handles this kind of validations.)

Greetings,
Stefan

-- 
You received this message because you are subscribed to the Google Groups "Hobo 
Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/hobousers.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to