0

I have a database table that has a column that I need as an array.

I've gathered the records I need with:

app.rb

@liquor = Venue.find(@venue.id).liquors_venues.where(:venue_id => @venue.id)

and I can view the data I want with:

view.erb

<% @liquor.each do |liquor| %> <%= liquor.liquor_id %><% end %>

This only gives me the data I want by running the loop. I really need @liquor.liquor_id, but as liquor_id is in a subarray, it's inaccessible. I need an array so I can run this code to determine whether a checkbox is checked or not:

view.erb

<%= @liquor.include?(vodka.id) ? "checked" : "" %>

1 Answer 1

1

You can put it into an array...

all_liquor_ids = @liquor.map { |liquor| liquor.liquor_id }

<%= all_liquor_ids.include?("vodka.id") ? "checked" : "" %>

Hope this helps.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.