user4965201
user4965201

Reputation: 973

Ruby on rails fetch the multiple values stored in the record

I have a column in record which is looking_job in which i am storing multple values, by seeing into the parameters i get

looking_job: "[\"office\", \"fieldwork\"]"

this columne is stored in the profiles table

so that

@profile = Profile.where(individual_id: params[:individual_id]).first

when i print the

<%= @profile.looking_job  %> 

in the view i am getting the output as ["office", "fieldwork"]

but i want it to show like - office, fieldwork

how can i get it ? thankx in advance

Upvotes: 0

Views: 73

Answers (1)

Aleksei Matiushkin
Aleksei Matiushkin

Reputation: 121000

▶ looking_job = "[\"office\", \"fieldwork\"]"
#⇒ "[\"office\", \"fieldwork\"]"
▶ require 'json'
#⇒ true
▶ JSON.parse(looking_job).join(', ')
#⇒ "office, fieldwork"

Upvotes: 1

Related Questions