[英]Is it possible to use values in a <span> as the parameters for a Ruby function?
I'm passing a span to an HTML file from a javascript file using: 我正在使用以下命令从JavaScript文件将跨度传递到HTML文件:
$('#eventCode').html event.code
From said HTML file I'm displaying the contents of the selected code with: 从上述HTML文件中,我将使用以下命令显示所选代码的内容:
<span id="eventCode"></span>
This works fine, but I also am trying to make a ruby function call as follows: 这工作正常,但我也尝试按如下方式进行ruby函数调用:
<%= 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? 如上所示,有什么办法可以获取HTML跨度的内容并将其用作Ruby函数的参数?
Since your link_to
tag is just a HTML <a>
tag being rendered, you could pass your event.code
directly to that tag ? 由于您的
link_to
标签只是呈现的HTML <a>
标签,因此您可以将event.code
直接传递给该标签?
Uniquely identify your link with an id: 用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: 并使用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. 再次考虑,如果您想直接将代码名传递给
Event.find_by_code("codename")
那么您将无法这样做。 In that case, you should handle this in a controller ahead of calling this probably. 在这种情况下,您应该在调用它之前在控制器中处理此问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.