Is there a way to use ActionView Helpers in Coffeescript/Javascript in Rails 4? -
for example, if want in kites.js.coffee:
= select_tag :kite, options_for_select([["kite1","1"],["kite2","2"]], selected: nil), {class: 'form-control', name: "kite[tail]"}
where kite_options = [["kite1","1"],["kite2","2"], etc.]
the whole point not have manually write javascript code reads like:
js_variable = "<select>....<option>kite1</option></select>";
you should not that, if include ruby code in cofeescript templates, have performance overhead compiling cofeescript on every request. that's reason don't have easy way include ruby code coffeescript, intentional avoid such thing.
you can serve javascript variables views, , use them within coffeeescript template:
javascript: var options_for_select = '#{options_for_select([["kite1","1"],["kite2","2"]]}'; coffee: $(document).ready -> alert(options_for_select);
Comments
Post a Comment