Hi Fred,

Thanks for your response.

render :update
Ive got quite a few Ruby conditions and styling going in the js.erb
file im using now to display the contact information. And ive got more
possibilities than the 3 ive shown above in the controller. So this
might not be the right option for me. Right?

observe_field callback
This might work for me. Right now, the only callbacks I have on the
observe_field are showing and hiding the spinner. I have never written
custom callbacks on Rails JS helpers. Could you help me through this?

So im guessing I should be having something like this

<%= observe_field 'contact_id', :frequency => 0.5, :update =>
'info', :before => "Element.show('spinner')",
                :success => "handle_contact_request(value);", :url =>
show_contact_path,:method =>:get,
                :with => 'contact_id' %>

and in application.js

function handle_contact_request(value){

         Element.hide('spinner');
         if value=="new contact"
         {
                //how do i redirect to the New Contact page?
         }
         else
         {
               //show contact info. But how do I handle the conditions
and styling??
         }
}

Am I getting the basic idea right? If yes, how can I handle the
conditional redirecting and the rest in Javascript?
Thanks again Fred.

On Apr 8, 12:20 pm, Frederick Cheung <[email protected]>
wrote:
> On Apr 8, 6:51 am, Ram <[email protected]> wrote:
>
>
>
> > Hi all,
>
> > I have select box in one of my views which lists a few contacts.
> > I also have an option in this select box to add a new contact.
> > There is also an observe_field hook to this select box that Ajax
> > requests further info about the selected contact from the controller
> > and displays it in an adjacent "info" div.
>
> > Now, I need to redirect the user to the New Contact page from the
> > controller if the selected value from the select box is "new contact".
>
> > This is the controller code I have now
> > ....
> > if request.xml_http_request?
> >   if [email protected]?
> >     render :partial => "show", :layout => false
> >   elsif params[:id] == "new contact"
> >     redirect_to new_contact_path
> >   else
> >     render :text => "Please select a contact"
> >   end
> > end
>
> > This renders the New Contact page in the "info" div. Whereas, I want
> > the user to be completely redirected to the New Contact page like a
> > HTTP response would.
> > Any thoughts on how I can handle this? Any ideas welcome..
> > Thanks!
>
> Two ways of doing this: either the observe_field thingy has a callback
> that redirects in the right circumstances or you switch to using
> render :update (and then use page.redirect_to), In the latter case you
> have to use render :update for all of these 3 possibilities and you
> need to change your observe_field invocation to not pass the :update
> option.
>
> Fred
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to