# Observe\_field synchronous request

**URL:** <https://www.ruby-forum.com/t/observe-field-synchronous-request/140446>\
**Category:** Rails\
**Created:** [June 14, 2008, 5:11am UTC](https://www.ruby-forum.com/t/observe-field-synchronous-request/140446 "2008-06-14T05:11:28Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![indigoi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/b3f665/32.png) [@indigoi](https://www.ruby-forum.com/u/indigoi)\
**Post date:** [June 14, 2008, 5:11am UTC](https://www.ruby-forum.com/t/observe-field-synchronous-request/140446/1 "2008-06-14T05:11:28Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![indigoi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/b3f665/32.png) [@indigoi](https://www.ruby-forum.com/u/indigoi)\
**Post date:** [June 14, 2008, 12:38pm UTC](https://www.ruby-forum.com/t/observe-field-synchronous-request/140446/2 "2008-06-14T12:38:33Z")

</div>

On 14 Jun 2008, at 04:11, Richard S. wrote:

> \<%= 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

---

<div class="post-metadata">

**Author:** ![indigoi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/b3f665/32.png) [@indigoi](https://www.ruby-forum.com/u/indigoi)\
**Post date:** [June 14, 2008, 5:46pm UTC](https://www.ruby-forum.com/t/observe-field-synchronous-request/140446/3 "2008-06-14T17:46:37Z")

</div>

Frederick C. wrote:

> On 14 Jun 2008, at 04:11, Richard S. 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!!

---

<div class="post-metadata">

**Author:** ![indigoi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/b3f665/32.png) [@indigoi](https://www.ruby-forum.com/u/indigoi)\
**Post date:** [June 14, 2008, 6:01pm UTC](https://www.ruby-forum.com/t/observe-field-synchronous-request/140446/4 "2008-06-14T18:01:35Z")

</div>

> 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

---

<div class="post-metadata">

**Author:** ![indigoi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/b3f665/32.png) [@indigoi](https://www.ruby-forum.com/u/indigoi)\
**Post date:** [June 14, 2008, 6:48pm UTC](https://www.ruby-forum.com/t/observe-field-synchronous-request/140446/5 "2008-06-14T18:48:29Z")

</div>

> 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  
be changed, page.redirect\_to looks promising, but i’m not familiar with  
rjs implementation. 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  
can’t find any info on it online. can you point me to an example?

---

<div class="post-metadata">

**Author:** ![indigoi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/b3f665/32.png) [@indigoi](https://www.ruby-forum.com/u/indigoi)\
**Post date:** [June 14, 2008, 7:06pm UTC](https://www.ruby-forum.com/t/observe-field-synchronous-request/140446/6 "2008-06-14T19:06:10Z")

</div>

On 14 Jun 2008, at 17:48, Richard S. wrote:

> > 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
