0

I want to create a form that will add fields dynamically based on buttons the user clicks on. I am able to append raw HTML code, but erb code isn't properly being rendered.

Coffeescript Code:

field = '<%= hello %>'

$ ->
    $('button').click ->
        $('#tests').html(field)

When I click on the button, the entire string <%= hello %> is printed on the page. What do I need to add to ensure that the string I'm passing in is interpreted as erb code? Thank you

4

1 回答 1

1

将 .erb 添加到您的 .coffee 文件中。

所以,my_file.js.coffee 变成了 my_file.js.coffee.erb

于 2013-09-05T23:28:42.277 回答