user1774481
user1774481

Reputation: 193

no implicit conversion of Symbol into Integer ruby on rails

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

Answers (2)

Prashant4224
Prashant4224

Reputation: 1601

Please change the code

@event.prices.pluck(: full_price)

It displays array price list

Hope it helps!

Upvotes: 0

ivalkeen
ivalkeen

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:

  • Take the first or the last price: @event.prices.last.full_price
  • Map prices into array and make a comma-separated string out of it: @event.prices.map(&:full_price).join(", ")
  • Change your association to has_one to make @event.price be an object, not a collection
  • ... many others

Hope that helps.

Upvotes: 2

Related Questions