1

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

Can I set the update_path value of render partial parameters?

skadoosh
  • 471
  • 1
  • 6
  • 15
  • The syntax would be `render(:partial =>'abc', :locals => { update_path => 'path' })` – MrYoshiji Sep 20 '13 at 13:21
  • not clear, could you please add more information? – Muntasim Sep 20 '13 at 13:25
  • @MrYoshiji His syntax actually works fine. See http://api.rubyonrails.org/classes/ActionView/Helpers/RenderingHelper.html#method-i-render - "If no options hash is passed or :update specified, the default is to render a partial and use the second parameter as the locals hash" – Dylan Markow Sep 20 '13 at 13:26
  • @MrYoshiji I am in a view where I render this partial. I need to send the location of the current view, through js, as value for the update_path parameter – skadoosh Sep 20 '13 at 13:37
  • You can't really do that, JS is executed on the client side (browser) whereas the ruby code is executed on the server-side – MrYoshiji Sep 20 '13 at 13:40
  • Thanks, forgot this basic rule.. I guess I can probably create a hidden field in partial, and then update it accordingly. – skadoosh Sep 20 '13 at 13:46

1 Answers1

0

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=... (i.e. 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.

Community
  • 1
  • 1
Dylan Markow
  • 123,080
  • 26
  • 284
  • 201