ruby on rails - How to get database to read form value, not option number -
for profile fields such ethnicity. user 1 has selected 'asian' ethnicity. in users database show numbers selected ethnicity (such asian = 1, dutch = 2, etc based on order of ethnicities options list) , search database recognizes ethnicity itself...not number ethnicity. search trying find users asian selected, technically there none since user database goes number instead of name of ethnicity.
i believe user database showing numbers because what's used in form best_in_place gem.
show.html:
<p>ethnicity: <%= best_in_place @user, :ethnicity, nil: 'what ethnicity?', :type => :select, :collection => [[1, "asian"], [2, "biracial"], [3, "indian"], [4, "hispanic/latin"], [5, "middle eastern"], [6, "native american"], [7, "pacific islander"], [8, "white"], [9, "other"]] %></p>
i have tried doing:
collection: ["asian", "biracial", "indian"]
and
collection: [ ["asian", "asian"], ["biracial", "biracial"], ["indian", "indian"]]
if first example option should read 'asian' instead read "s".
the second example doesn't display option, it's blank drop down box.
does know how can these options save user database actual option oppose numbers?
schema:
create_table "searches", :force => true |t| t.string "gender" t.string "age" t.string "zip_code" t.string "children" t.string "religion" t.string "ethnicity" t.datetime "created_at", :null => false t.datetime "updated_at", :null => false end create_table "users", :force => true |t| t.string "email" t.string "password_digest" t.string "zip_code" t.string "birthday" t.string "name" t.string "username" t.string "gender" t.string "ethnicity" t.string "sexuality" t.string "career" t.string "education" t.string "religion" t.string "politics" t.string "children" t.string "height" t.string "user_smoke" t.string "user_drink" t.string "about_me" t.string "inches" t.string "feet" t.datetime "created_at", :null => false t.datetime "updated_at", :null => false t.string "auth_token" t.string "password_reset_token" t.datetime "password_reset_sent_at" t.boolean "admin" t.string "role" t.integer "roles_mask" t.string "age" t.string "age_end" end
i figured problem out. best in place code fine, needed modify search form.
<%= f.select :ethnicity, [["asian", "1"], ["biracial", "2"], ["indian", "3"], ["hispanic/latin", "4"], ["middle eastern", "5"], ["native american", "6"], ["pacific islander", "7"], ["white", "8"], ["other", "9"]], :include_blank => true %>
as can see added value it's showing in database after name of ethnicity. pulls searches perfectly.
Comments
Post a Comment