List Info

Thread: problem with multipe id key in a table




problem with multipe id key in a table
country flaguser name
United States
2007-08-04 09:46:11
I've 3 tables:
"monsters", "movements" and
"ana_movements". "monsters" contains
creatures who can have many movements (description is
'swim', 'walk',
'run', and so on) with differents values represented by
numeric
values. Numeric value is stored in "movements"
while description in
"ana_movements" so i can have same description
with different monster
without duplicate my data.
For example a goblin may run 12 feet and walk 9 feet. In my
table I'll
have:

monsters
movements                                  ana_movements
id: 49                                 id:
37                                            id: 546
name: goblin                    value:
12                                       description: run
                                         monster_id: 49
                                         ana_movement_id:
546                 id: 644
 
description: walk
                                         id: 38
                                         values: 9
                                         monster_id: 49
                                         ana_movement_id:
644


I've a form who should update all my tables during update
but when i
save it updates monsters and my record in movements has no
ana_movement_id updated!

this is my update in the controller


 def update
    monster = Monster.find(params[:id])
    monster.attributes = params[:monster]
    monster.movements.each{ |t| t.attributes =
params[:movement]
[t.id.to_s]}
    if monster.valid?  &&  monster.movements.all?(&:valid?)
      monster.movements.each(&:save!)
      redirect_to :action => 'show', :id => monster
    else
      render :action => 'edit'
    end

  end


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Ruby on Rails" group.
To post to this group, send email to rubyonrailsgooglegroups.com
To unsubscribe from this group, send email to
rubyonrails-unsubscribegooglegroups.com
For more options, visit this group at http://gro
ups.google.com/group/rubyonrails
-~----------~----~----~----~------~----~------~--~---


Re: problem with multipe id key in a table
country flaguser name
United States
2007-08-04 12:52:58
I'm sorry my post was bad formatted. Now I'll repost with
right
justification.
 I've 3 tables:
 "monsters", "movements" and
"ana_movements". "monsters" contains
 creatures who can have many movements (description is
'swim', 'walk',
 'run', and so on) with differents values represented by
numeric
 values. Numeric value is stored in "movements"
while description in
 "ana_movements" so i can have same description
with different monster
 without duplicate my data.
 For example a goblin may run 12 feet and walk 9 feet. In my
table
I'll
 have:

 monsters
id: 49
name: goblin
movements

id: 37
value: 12
monster_id: 49
ana_movement_id: 546

id: 38
value: 9
monster_id: 49
ana_movement_id: 644

ana_movements:

id:546
description: run

id: 644
description: walk



 I've a form who should update all my tables during update
but when i
 save it updates monsters and my record in movements has no
 ana_movement_id updated!

 this is update in the controller


 def update
     monster = Monster.find(params[:id])
     monster.attributes = params[:monster]
     monster.movements.each{ |t| t.attributes =
params[:movement]
[t.id.to_s]}
     if monster.valid?  &&  monster.movements.all?(&:valid?)
       monster.movements.each(&:save!)
       redirect_to :action => 'show', :id => monster
     else
       render :action => 'edit'
     end

  end

can you help me?


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Ruby on Rails" group.
To post to this group, send email to rubyonrailsgooglegroups.com
To unsubscribe from this group, send email to
rubyonrails-unsubscribegooglegroups.com
For more options, visit this group at http://gro
ups.google.com/group/rubyonrails
-~----------~----~----~----~------~----~------~--~---


[1-2]

about | contact  Other archives ( Real Estate discussion Medical topics )