Reputation: 193
I have a small problem I try to display information that is in my prices table that is my relationship with table event.
So in my table event: has_many: prices
So in my table price: belongs_to: event
I get an error: no implicit conversion of Symbol into Integer
I do not understand why because I actually like this to display the price
@event.prices [: full_price]
Here the entrance to my table price:
[#<Price id: 4, full_price: 30, params: ["10", "etudiant et chomeurs"], event_id: 12, created_at: "2015-06-28 20:23:15", updated_at: "2015-06-28 20:23:15">]>
Upvotes: 1
Views: 1033
Reputation: 1601
Please change the code
@event.prices.pluck(: full_price)
It displays array price
list
Hope it helps!
Upvotes: 0
Reputation: 1411
You have created has_many
association which means that for @event
you'll have many prices.
So @event.prices
is a collection of prices, but you are trying to access it as a Hash. I don't know what logic you need, but you can:
@event.prices.last.full_price
@event.prices.map(&:full_price).join(", ")
has_one
to make @event.price
be an object, not a collectionHope that helps.
Upvotes: 2