I'm passing a span to an HTML file from a javascript file using:
$('#eventCode').html event.code
From said HTML file I'm displaying the contents of the selected code with:
<span id="eventCode"></span>
This works fine, but I also am trying to make a ruby function call as follows:
<%= link_to "Delete", Event.find_by_code("eventCode would go here"),
method: :delete, confirm: "Are you sure you want to delete the event?" %>
Is there any way I can take the contents of a HTML span and use them as a parameter for a Ruby function, as shown above?
Since your link_to
tag is just a HTML <a>
tag being rendered, you could pass your event.code
directly to that tag ?
Uniquely identify your link with an id:
<%= link_to "Delete", "Code name soon to be replaced", id: "eventCode-delete-link", method: :delete, confirm: "Are you sure you want to delete the event?" %>
and do something like this with your JS:
$('#eventCode-delete-link').html event.code
Would that work for your use case ?
EDIT
On second thought, if you want to pass your code name directly into Event.find_by_code("codename")
then you won't be able to. In that case, you should handle this in a controller ahead of calling this probably.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.