Hi all, I am new in Rials, I have problem to assign the first name from (model - name1) to first-name (model name2) cuz when i create a name in table name1, i want it appears in table name2 and my model relationship is: model name1 - ( has_one :name2) model name2 = (belongs_to :name) please help. thanks -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
First, I don''t really understand the logic to do that. But, OK, it''s up to you to define it. If you have the attribute ''first_name defined both in the two models, you should do something like this: model_name1 = Name1.create(:first_name=>''toto'') model_name2 = Name2.new model_name2.first_name = model_name1.first_name model_name2.save! model_name1.model_name2 = model_name2 See more details on Ruby on Rails guides here: http://guides.rubyonrails.org/ On Jun 2, 8:11 pm, joanne <joanne0...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi all, > > I am new in Rials, I have problem to assign the first name from (model > - name1) to first-name (model name2) > > cuz when i create a name in table name1, i want it appears in table > name2 > > and my model relationship is: > > model name1 - ( has_one :name2) > model name2 = (belongs_to :name) > > please help. > > thanks-- 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.
On 2 June 2011 19:11, joanne <joanne0558-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi all, > > I am new in Rials, I have problem to assign the first name from (model > - name1) to first-name (model name2) > > cuz when i create a name in table name1, i want it appears in table > name2 > > and my model relationship is: > > model name1 - ( has_one :name2) > model name2 = (belongs_to :name)If you mean that you have two tables, both with a ''name'' column and you want the same data in both columns then I advise against this. It is generally a bad idea to have the same data in two tables in the database, you have to be very careful to keep them the same when the name is edited for example. Also there is no need since you have defined a relationship between the tables. So if you have a name1 record in @name1 and the name column is in table name2 then you can say @name1.name2.name to get the name. Colin -- 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.