catburston / townbikes

Ironhack Web Development Bootcamp final project. Townbikes is a platform to rent your unused bicycle to travellers or find the best bicycle for your needs when you are travelling.
1 stars 1 forks source link

Adding a bicycle not working #2

Closed mediafinger closed 10 years ago

mediafinger commented 10 years ago

Error message and stack trace:

Showing /Users/andy/www/townbikes/app/views/bicycles/show.html.erb where line #13 raised:

undefined method `location' for #<User:0x007ffa042105b0>
Extracted source (around line #13):          
10       Description: <%= @bicycle.description %><br />
11       User ID: <%= @bicycle.user_id %><br />
12      Owner: <%= link_to "#{@owner.first_name} #{@owner.last_name}", user_path(@owner.id) %><br />
13       Location: <%= @owner.location %><br />
14       <%= link_to 'Reserve this Bicycle', new_reservation_path(reservation: { bicycle_id: @bicycle.id} ) %>
15     </li>
16   </ul>

My guess: you have to change the relation from has_many :locations to has_one :location on the User model.

mediafinger commented 10 years ago

Same issue on: Showing /Users/andy/www/townbikes/app/views/reservations/index.html.erb where line #11 raised

mediafinger commented 10 years ago

And: /Users/andy/www/townbikes/app/views/bicycles/index.html.erb

catburston commented 10 years ago

It's because of the "Location: <%= @owner.location %>". I can't get the bicycle to relate to the location properly...

mediafinger commented 10 years ago

Read the last sentence of my initial posting in this issue again.

You have no "location" on your owner. You have "locations". And that is not what you want.