On Sep 22, 2008, at 3:58 PM, Becca Girl wrote:
> Ok, here's what I have in my models.
>
> class Review < ActiveRecord::Base
>  belongs_to :reviewable, :polymorphic => true
>  belongs_to :created_reviews, :class_name => 'User', :foreign_key =>
> 'create_review_user_id'
This would be clearer as something singular (like 'reviewer') since a  
belongs_to is going to give a single associated record.

>
>  belongs_to :modified_reviews, :class_name => 'User', :foreign_key =>
> 'modify_review_user_id'
> end
>
> class User < ActiveRecord::Base
>  has_many :reviews, :as => :reviewable
>  has_many :created_reviews, :foreign_key => 'create_review_user_id'
>  has_many :modified_reviews, :foreign_key => 'create_review_user_id'
Perhaps you meant for the second one to be 'modify_review_user_id'?
>
>
>
> Sorry I'm so dense, but after all of that, how do I access User.name?

On Sep 22, 2008, at 4:27 PM, Becca Girl wrote:

>
> Maurício Linhares wrote:
>> review.created_reviews.name
>>
>
> I wasn't sure where this should all go, but I am still getting errors.
> Here's what I did in script/console:
>
>>> Book.find(1).reviews
>
> => [<#Review id: 2, reviewable_type: "Book", reviewable_id: 1,
> create_review_user_id: 1>]
>
>
>>> review.created_reviews.name
>
> => NameError: undefined local variable or method `review' for
> #<Object:0x18fa38>
>        from (irb):9

review = Book.find(1).reviews.first

>
>
> If I put this in, I also get an error.
>
>>> Book.find(1).reviews.each do |r|
> ?> puts review.created_reviews.name
>>> end
> NameError: undefined local variable or method `review' for
> #<Object:0x18fa38>
>        from (irb):11

Close, try:
Book.find(1).reviews.each do |review|
then the block will have a variable named review (rather than the r in  
your first attempt)

> Clearly I'm lost and confused.  Thanks for helping out this new ruby
> girl.


Be aware that your confusion seems to be a mix of Rails (specifically,  
ActiveRecord) conventions and Ruby syntax.

-Rob

Rob Biedenharn          http://agileconsultingllc.com
[EMAIL PROTECTED]


--~--~---------~--~----~------------~-------~--~----~
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