javascript - Save CoffeeScript json object data inside a Rails variable -
i have js.coffee.erb file , in file there function gets 'equipment' json object (in javascript) , pastes of data html.
json object saved in variable called eqp
.
each equipment has category
(reference other table object).
in json object, there equipment.category_id
, category name wrote statement:
$("#display_equipment_category_value").html <%= category.find(eqp.category_id).name %>
the problem can't defined rails variable called eqp
because it's not rails object.
how save js json eqp.category_id
inside rails variable?
set_equipment = (eqp) -> <% cat_id = ????? %> - # save eqp.category_id cat_id $("#display_equipment_category_value").html <%= category.find(cat_id).name %>
i'm not sure if it's correct answer because seems ineffective, works fine i'll use it:
set_equipment = (eqp) -> // creating empty string variable result category name cat = ""; // bringing categories db , save them json object <% all_cat = category.all %> categories = <%= all_cat.to_json %> // comparing each category equipment category_id $.each categories, (i, v) => cat = v.name if (v.id == eqp.category_id) // display category name in html $("#display_equipment_category_value").html cat
Comments
Post a Comment