Hi.  I believe that I need to write a method to get my user's
information, but I'm not sure how to write this and where it should go.

I have Reviews as polymorphic and there are several types items that can
be reviewed (books, music, movies, etc).  A user can search for a book
and see all of the reviews for that book.  Posted with each review, I
want to provide the name of the user.  Based on what I have, what is the
best way to do this and where does this code go?  Right now if I pull up
the book, I can see all of the reviews.  In the review table I have the
review_user_id and now I want to display the name of that user from the
users table.

Here's my basic structure, but noting that I have put snippets of the
data here for brevity.

class CreateReviews < ActiveRecord::Migration
  def self.up
    create_table :reviews
      t.string :reviewable_type
      t.integer :reviewable_id
      t.string :title
      t.text   :body
      t.integer :review_user_id
    end
  end
end


class CreateUsers < ActiveRecord::Migration
  def self.up
    create_table :users
      t.string :name
    end
  end
end


class Review < ActiveRecord::Base
  belongs_to :reviewable, :polymorphic => true
end

class Book < ActiveRecord::Base
  has_many :reviews, :as => reviewable
end


class User < ActiveRecord::Base
  has_many :reviews, :as => :reviewable
end



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 [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to