I'm in the middle of building my first real Rails application, and I'm learning along the way. I have a situation where I need to create nested attributes in one form, and therefore they consider railscast episodes related to this (196 and 197). In the second episode, he uses the link_to_function method, which is apparently no longer available in rails 4.1.
I wonder how to replace it. I am trying to set link_to and have tried many of the suggested solutions for others that posted a similar question but to no avail.
This is how my view partially looks (although, I tried a lot of things ...)
<p class="offset1 fields"> <%= f.hidden_field :_destroy %> <%= link_to "remove", '#', onclick: 'remove_fields("this")' %> </p>
And here is my .js.coffee file containing the remove_fields () function:
remove_fields = (link) -> $(link).previous("input[type=hidden]").value = 1 $(link).up(".fields").hide
This function should remove the field from the form, but instead simply appends '#' to the URL without calling the function.
What is the best way to reference javascript (coffeescript) function in assets from view?
source share