如何从站点 Rails 3 动态获取 link_to 的参数
我正在 Rails 中以不显眼的 jQuery 方式使用 link_to 方法:
<%= link_to "save",
update_elements_diagram_path(diagram, :shown_elements => ["speed", "position_break"]),
:method => :post, :remote => true, :class => "close",
:onclick => "stringViewsTableLoading()" %>
这有效。但现在我想从用户输入中动态获取参数“shown_elements”。 我知道如何将它们从表单转换为 javascript,但是如何从 javascript 转换为 Rails?
... shown_elements => "getShownElements()"
或者类似的东西会很棒。
问候
桑德罗
I am using a the link_to method in Rails the unobstrusive jQuery way:
<%= link_to "save",
update_elements_diagram_path(diagram, :shown_elements => ["speed", "position_break"]),
:method => :post, :remote => true, :class => "close",
:onclick => "stringViewsTableLoading()" %>
This works. But now I want to get the arguments "shown_elements" dynamically from the users inputs.
I know how to get them from the form to javascript, but how from javascript to Rails?
... shown_elements => "getShownElements()"
or something similar would be great.
Greetings
Sandro
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不确定我明白你的意思,所以我猜你的页面上有一些字段,而你想要的是在
:shown_elements
中获取这些字段的值。这不是应该做的事情。反过来想想。您正在使用
:method => 发布表单:post
,这意味着可以使用params[]
在目标控制器中访问这些内容。希望这有帮助!
Not sure I see what you mean there, so I guess that you somehow have a few fields on your page, and that what you want is to get the value of those fields in the
:shown_elements
.This is not how it's supposed to be done. Think the other way around. You are posting a form using
:method => :post
, which means that those will be accessible in your target controller usingparams[]
.Hope this helps!