# Can't access model method in view

**URL:** <https://www.ruby-forum.com/t/cant-access-model-method-in-view/144585>\
**Category:** Rails\
**Created:** [July 31, 2008, 8:54am UTC](https://www.ruby-forum.com/t/cant-access-model-method-in-view/144585 "2008-07-31T08:54:29Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![hangingclowns](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/b5e925/32.png) [@hangingclowns](https://www.ruby-forum.com/u/hangingclowns)\
**Post date:** [July 31, 2008, 8:54am UTC](https://www.ruby-forum.com/t/cant-access-model-method-in-view/144585/1 "2008-07-31T08:54:29Z")

</div>

In the console:

> > act = Activity.find\_by\_id(37)  
> > =\> #\<Activity id: 37, created\_at: “2008-07-30 05:08:41”, updated\_at:  
> > “2008-07-30 05:08:41”, location\_id: 1, scheduled\_at: nil\>
> 
> > act.location  
> > =\> #\<Location id: 1, name: “Bar Austin”, genre: 1, age\_group: 1, notes:  
> > “First Bar Added to Test”, created\_at: “2008-07-29 04:15:47”,  
> > updated\_at: “2008-07-29 04:15:47”, street1: “402 E. 6th Street”,  
> > street2: nil, city: “Austin”, state: “TX”, zip: “78701”, phone\_number:  
> > “(512) 476-3139”, image\_url: “locations/bars/image1.jpg”, website\_url:  
> > nil, average\_rating: 3.0\>

* * *

In the view when I try to do:

\<%= debug(@activities) %\>  
\<% for activity in @activities %\>  
\<%= debug(activity.location) %\>  
\<% end %\>

I get the error:  
NoMethodError in Public#index

Showing public/index.fbml.erb where line #7 raised:

undefined method `location’ for #Class:0xb7106258

Extracted source (around line #7):

4:  
5: \<% for activity in @activities %\>  
6:  
7: \<%= debug(activity.location) %\>

Taking out the ‘debug(activity.location)’ line and just showing the  
debug output of the activities array:

* * *

- 
  - !ruby/object:Activity  
attributes:  
updated\_at: 2008-07-30 23:22:49  
activity\_id: “52”  
id: “52”  
location\_id: “1”  
user\_id: “1”  
scheduled\_at: 2008-07-25 04:00:00  
created\_at: 2008-07-30 23:22:49  
attributes\_cache: {}

  - !ruby/object:Activity  
attributes:  
updated\_at: 2008-07-31 04:14:18  
activity\_id: “54”  
id: “54”  
location\_id: “1”  
user\_id: “1”  
scheduled\_at: 2008-07-31 04:00:00  
created\_at: 2008-07-31 04:14:18  
attributes\_cache: {}

- 
  - !ruby/object:Activity  
attributes:  
updated\_at: 2008-07-31 02:34:23  
activity\_id: “53”  
id: “53”  
location\_id: “4”  
user\_id: “2”  
scheduled\_at: 2008-08-01 04:00:00  
created\_at: 2008-07-31 02:34:23  
attributes\_cache: {}

---

<div class="post-metadata">

**Author:** ![hangingclowns](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/b5e925/32.png) [@hangingclowns](https://www.ruby-forum.com/u/hangingclowns)\
**Post date:** [July 31, 2008, 9:11am UTC](https://www.ruby-forum.com/t/cant-access-model-method-in-view/144585/2 "2008-07-31T09:11:36Z")

</div>

nevermind, i was appending an array to arrays and it was trying to call  
a method on an array and not an object.
