Ruby on Rails Tuesday, May 29, 2012

Thanks Jeremy, your code got me rolling. I will be doing more reading http://guides.rubyonrails.org/association_basics.html

On Tue, May 29, 2012 at 9:00 AM, Jeremy Walker <jez.walker@gmail.com> wrote:


On 29 May 2012 13:26, Steve Knit <lists@ruby-forum.com> wrote:
Hello Jeremy, thanks for providing me your experience and quick
response!

You're welcome! So you know, it's customary to post your responses in the relevant place of a thread, rather than top-posting. It makes the conversation easier to follow.
 

Here is my migration, sorry for being such a newb....


[loluser@fedora migrate]$ cat 20120527225053_create_pets.rb
class CreatePets < ActiveRecord::Migration
 belongs_to  :admin
 def self.up
   create_table :pets do |t|
     t.string :location
     t.string :public_key

     t.timestamps
   end
 end

 def self.down
   drop_table :pets
 end
end

You have the "belongs_to :admin" method in the wrong place. I'm interested that this even runs! 

Your create_table block should look like this:

   create_table :pets do |t|
     t.belongs_to  :admin

     t.string :location
     t.string :public_key

     t.timestamps
   end

In this context, the belongs_to is part of the database creation schema and so must be placed within the create_table call.

Try changing that and then redoing the migration (rake db:migrate:redo) and see whether that fixes things.

 

--
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@googlegroups.com.
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.


--
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@googlegroups.com.
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.

--
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@googlegroups.com.
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.

No comments:

Post a Comment