简体   繁体   中英

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? eg
<%= render('abc', :update_path => 'path') %>

Can I set the update_path value of render partial parameters?

Is there a reason you need to use JavaScript for this? If not, you can access the current full URL directly through Rails:

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). If you only need the path portion, you can do request.fullpath which would give you /my_controller/my_action?my_params=... .

See How do I get the current absolute URL in Ruby on Rails? for more info.

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.

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