5

I'm developing project on rails 2.3.8 and I need to refresh the whole web page when user select particular selection on drop-down menu. How can I do it on rails ?

This is my drop down menu

  <%= collection_select("country", "id", @countries , :id, :name, {:prompt => true}, :id => 'xx') %>
  <%= observe_field('xx', :url => { :controller => 'calendar', :action => 'update_country' },:update => 'app_header',:with => "'con=' + escape(value)")%>

This finely load the countries so how I can reload the whole page ? please can some one explain me about this?

SL_User
  • 1,934
  • 5
  • 24
  • 45

2 Answers2

3

Simply add a html option to your collection select , onchange => "Javascript code to reload the page"

<%= collection_select("country", "id", @countries , :id, :name, {:prompt => true}, :id => 'xx', :onchange => "location.href = '#{root_url}'") %>
Ross
  • 1,562
  • 1
  • 15
  • 26
  • Hay thanks for your rply. Can you please explain how to put URL on there. Can I use root_path as url ? – SL_User Oct 14 '11 at 08:59
  • Hay can call to particular method on controller file and then redirect to different URL ? – SL_User Oct 14 '11 at 10:56
  • Yes you can do that as well , in place of root_url you can specify your own custom url – Ross Oct 14 '11 at 12:04
  • Actually I need to reload the web page after doing the stuff in "update_country" method on 'calendar' controller. How can I do that on controller ? – SL_User Oct 17 '11 at 03:11
0

Or you can just refresh the current page:

<%= collection_select("country", "id", @countries , :id, :name, {:prompt => true}, :id => 'xx', :onchange => "location.href = window.location.href") %>
spirito_libero
  • 1,206
  • 2
  • 13
  • 21