observe_field synchronous request

I am using an observe field that completely re-renders a page based on what language the user selects. I would like to do this and force the action into a sychronous action so when the user wants to copy the url and e-mail it to someone else, they get the same language. Any clue how to do this? If you can do it without observe_field, that would be fine with me, but it needs to happen as soon as the user picks a selection from the drop down menu.

<%= f.select_tag :show_language, options_for_select(["English", "French", "Spanish"]) %>

<%= observe_field(:show_language, :update => 'wrapper',:url => {:action => :search_language, :phrase => @phrase.word}, :frequency => 0.2, :on => 'focus', :with => "'language=' + encodeURIComponent(value)") %>

Using rails 2.0.2 and leopard 10.5.

I am using an observe field that completely re-renders a page based on what language the user selects. I would like to do this and force the action into a sychronous action so when the user wants to copy the url and e-mail it to someone else, they get the same language. Any clue
how to do this? If you can do it without observe_field, that would be fine with me, but it needs to happen as soon as the user picks a selection from the drop down menu.

<%= f.select_tag :show_language, options_for_select(["English", "French", "Spanish"]) %>

Have you tried using the select tag's onchange property (:onchange =>
remote_function(:url => {...}) ? What do you mean by forcing the action into a synchronous action ?

Fred

Frederick Cheung wrote:

<%= select_tag :show_language, options_for_select(["English", "French", "Spanish"]) %>

Have you tried using the select tag's onchange property (:onchange => remote_function(:url => {...}) ? What do you mean by forcing the action into a synchronous action ?

Fred

That is way simpler than using observe field thanks!

By "forcing a synchronous action" i meant that i wanted the page to refresh totally, with a new url and everything. When i use :onchange or observe_field, i can only :update => "a_portion_of_the_page" and my url doesn't change. So if a user used my select box to change the language from english to french and then coppied the url and sent it to someone else, when the other person clicked the url, it will incorrectly take them to the page marked as english. AJAX is awesome, but sometimes its a pain in the ass.

So if you know how to force the server to re-render the entire page even if the action is triggered with ajax, let me know, thanks!!

So if you know how to force the server to re-render the entire page even if the action is triggered with ajax, let me know, thanks!!

scrap the update and either: - in your rjs use page.redirect_to - or, don't use ajax at all (ie just write the onselect yourself. you can use update_page if you can't stand writing raw javascript)

Fred

scrap the update and either: - in your rjs use page.redirect_to - or, don't use ajax at all (ie just write the onselect yourself. you can use update_page if you can't stand writing raw javascript)

Fred

From the api, update_page doesn't look it can be used to force my
url to

update_page just creates a javascript generator (the think that rjs
uses), so for example

update_page do |page|    page.redirect_to ... end

will produce window.location = ..

be changed, page.redirect_to looks promising, but i'm not familiar
with rjs implementation.

page.redirect_to takes the same arguments as a 'normal' redirect_to

In rails 1.6 when passing a ajax call such as <%= link_to_remote %> it used to be as simple as passing :type => :synchronous in the code, but this doesn't seem to work anymore, and I

rails 1.6? I think you must be imagining things. A ajax request can
certainly be asynchronous or synchronous, but that's got nothing to do
with what you're after.

Fred