# Belongs\_to hackery

**URL:** <https://www.ruby-forum.com/t/belongs-to-hackery/124232>\
**Category:** Rails\
**Created:** [December 26, 2007, 8:14pm UTC](https://www.ruby-forum.com/t/belongs-to-hackery/124232 "2007-12-26T20:14:02Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![johnk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/59ef9b/32.png) [@johnk](https://www.ruby-forum.com/u/johnk)\
**Post date:** [December 26, 2007, 8:14pm UTC](https://www.ruby-forum.com/t/belongs-to-hackery/124232/1 "2007-12-26T20:14:02Z")

</div>

I have the following four files  
MODEL

class FriendshipRequest \< ActiveRecord::Base  
belongs\_to :user  
belongs\_to :requested\_by, :class\_name =\> :user, :foreign\_key =\>  
:requested\_by\_user\_id  
end

MIGRATION

create\_table :friendship\_requests do |t|  
t.references :user, :null =\> false  
t.integer :requested\_by\_user\_id, :null =\> false  
t.timestamps  
end

CONTROLLER

def index  
@user = User.find(session[:user])  
@friendship\_requests = FriendshipRequest.find(:all, session[:user])  
end

VIEW

\<% @friendship\_requests.each do |friendship\_request| -%\>  
\<%= friendship\_request.requested\_by.inspect %\>  
\<% end -%\>

And I am getting the following error:

can’t convert Symbol into String

Should I not be able to access the user through dot notation  
using riendship\_request.requested\_by?

What am I doing wrong?

Thanks!

–  
John K.  
removed\_email\_address@domain.invalid

Blog: [http://www.kopanas.com](http://www.kopanas.com)  
Conference: [http://www.cusec.net](http://www.cusec.net)  
Twits: [http://www.twitter.com/kopanas](http://www.twitter.com/kopanas)

---

<div class="post-metadata">

**Author:** ![johnk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/59ef9b/32.png) [@johnk](https://www.ruby-forum.com/u/johnk)\
**Post date:** [December 26, 2007, 8:48pm UTC](https://www.ruby-forum.com/t/belongs-to-hackery/124232/2 "2007-12-26T20:48:40Z")

</div>

2007/12/26, John K. :

> I have the following four files
> 
> MODEL
> 
> class FriendshipRequest \< ActiveRecord::Base  
> belongs\_to :user  
> belongs\_to :requested\_by, :class\_name =\> :user, :foreign\_key =\>  
> :requested\_by\_user\_id  
> end

:class\_name =\> ‘User’

– Jean-François.

---

<div class="post-metadata">

**Author:** ![johnk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/59ef9b/32.png) [@johnk](https://www.ruby-forum.com/u/johnk)\
**Post date:** [December 26, 2007, 8:48pm UTC](https://www.ruby-forum.com/t/belongs-to-hackery/124232/3 "2007-12-26T20:48:40Z")

</div>

On 26 Dec 2007, at 19:13, John K. wrote:

> I have the following four files
> 
> MODEL
> 
> class FriendshipRequest \< ActiveRecord::Base  
> belongs\_to :user  
> belongs\_to :requested\_by, :class\_name =\> :user, :foreign\_key  
> =\> :requested\_by\_user\_id  
> end

:class\_name expects a String

Fred
