i have two table, comment and post, both have composite keys, and no id column, comment belongs to post, i follow the instruction of http://compositekeys.rubyforge.org/, and it seems successfully, (But i still cant confirm to put require ''rubygems'' and require ''composite_primary_keys'' on which file ). I can do the CRUD operation for post,then i want to create comment form, in the _form.html.erb, the code likes below: <%= form_for([@post, @post.comments.build]) do |f| %> then i got an error,"unknown attribute: comment_id", i think the build method need the parameter id which is default, but i dont have this column,and i cant change any thing in the database,how to resolve this problem?Thanks . -- Posted via http://www.ruby-forum.com/. -- 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.
On 5 January 2012 02:53, Daisy Di <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> i have two table, comment and post, both have composite keys, and no id > column, comment belongs to post, i follow the instruction of > http://compositekeys.rubyforge.org/, and it seems successfully, > (But i still cant confirm to put require ''rubygems'' and > require ''composite_primary_keys'' on which file ). > I can do the CRUD operation for post,then i want to create comment form, > in the _form.html.erb, the code likes below: > <%= form_for([@post, @post.comments.build]) do |f| %> > then i got an error,"unknown attribute: comment_id", > i think the build method need the parameter id which is default, but i > dont have this column,and i cant change any thing in the database,how to > resolve this problem?Thanks .A way to resolve the problem is to stick to the rails conventions for id columns and so on. That is the best way unless you have a legacy database and *really* cannot change the schema. 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Colin Law wrote in post #1039519:> On 5 January 2012 02:53, Daisy Di <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote: >> dont have this column,and i cant change any thing in the database,how to >> resolve this problem?Thanks . > > A way to resolve the problem is to stick to the rails conventions for > id columns and so on. That is the best way unless you have a legacy > database and *really* cannot change the schema. > > ColinHi Colin, i really have a legacy database and cant change anything...... thanks very much -- Posted via http://www.ruby-forum.com/. -- 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.
On 6 January 2012 01:10, Daisy Di <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Colin Law wrote in post #1039519: >> On 5 January 2012 02:53, Daisy Di <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote: >>> dont have this column,and i cant change any thing in the database,how to >>> resolve this problem?Thanks . >> >> A way to resolve the problem is to stick to the rails conventions for >> id columns and so on. That is the best way unless you have a legacy >> database and *really* cannot change the schema. >> >> Colin > > Hi Colin, > i really have a legacy database and cant change anything...... > thanks very muchIn that case some of the clever stuff in Rails may not be available to you, you may have to do them ''by hand'' so to speak. I don''t know whether there is a way of using build in the way you want in your circumstance. The alternative is just to create the object explicitly. I expect you have already googled for rails legacy database to get as far as you have. 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.