Can't access model method in view

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: {}

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

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs