简体   繁体   English

如何将值从js传递到html.erb渲染函数

[英]How to pass value from js to html.erb render function

I have a partial to which I have to send a parameter -> update_path, which I get from javascript function window.location.href, is there a way I can do it? 我有一部分必须向我发送参数-> update_path,它是从javascript函数window.location.href中获得的,有什么办法可以做到? eg 例如
<%= render('abc', :update_path => 'path') %>

Can I set the update_path value of render partial parameters? 我可以设置渲染部分参数的update_path值吗?

Is there a reason you need to use JavaScript for this? 有没有你需要使用JavaScript一个原因? If not, you can access the current full URL directly through Rails: 如果没有,您可以直接通过Rails访问当前的完整URL:

render "abc", :update_path => request.original_url

request.original_url would give you something similar to http://mysite.com/my_controller/my_action?my_params=... (ie it includes the full url, not just the part after the host/port). request.original_url将为您提供类似于http://mysite.com/my_controller/my_action?my_params=... (即,它包含完整的 URL,而不仅仅是主机/端口之后的部分)。 If you only need the path portion, you can do request.fullpath which would give you /my_controller/my_action?my_params=... . 如果只需要路径部分,则可以执行request.fullpath ,它会给您/my_controller/my_action?my_params=...

See How do I get the current absolute URL in Ruby on Rails? 请参阅如何在Ruby on Rails中获得当前的绝对URL? for more info. 有关更多信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM