I have a form that triggers a remote GET request, leading to the display of a modal. The issue I'm facing is that multiple actions can utilize the same model, so I am attempting to employ a helper and jQuery to showcase different data based on what is being shown.
Below is the content of my add_users.js.erb file (executed after the remote GET request):
$('.modal-footer').html("<%= import_users_html %>");
Here is the structure of the helper:
def import_users_html
html = link_to '<i class="fa fa-download"></i> Import Users'.html_safe, '#', remote: :true, class: "btn btn-success btn-sm"
return html
end
However, when the HTML is returned, it fails to display within the <div class="modal-footer"
section. If I replace import_users_html
with "Hello World," everything works seamlessly.
There seems to be an issue somewhere with how the HTML is treated. Below is the actual content of the html
variable before it is sent back to the add_users.js.erb
view:
[2] pry(#<#<Class:0x00007f3bbe257050>>)> puts html
<a class="btn btn-success btn-sm" data-remote="true" href="#"><i class="fa fa-download"></i> Import Users</a>
I've attempted various solutions such as html_safe
, raw
, but none seem to resolve the issue for some reason.
** EDIT **
I discovered that the problem arises from link_to
converting the link to include double quotes, which conflicts with how I am using it in my add_users.js.erb
helper.