How to send back js.haml in rails

后端 未结 4 1909
一生所求
一生所求 2020-12-13 02:32

I have a rails create action which send back some jquery in a file:

create.js.erb

var appearance = $(\"<%= escape_javascript(rend         


        
4条回答
  •  情话喂你
    2020-12-13 03:02

    In a js.haml it would look something like

    != "var appearance = $('<%= escape_javascript(render(:partial => @appearance)) %>').effect('highlight', {color: '#E6ff00'}, 2000);"
    != "$('#sortable').append(appearance);"
    != "$('#new_appearance')[0].reset();"
    

    Note the HAML != syntax which prevents the generated text from being HTML escaped. I do agree that ERB is a better fit here, but for consistency stake you might still want to go the HAML way.

提交回复
热议问题