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

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -