I am trying to implement Craig Ambrose's Redbox for some form
submissions.
Ideally for me, when the user selects "Add contact" a redbox modal
window should open with the New Contact form and on submission, the
contacts select box on the main page should get updated with the newly
added contact.
I was looking into invoking Redbox from the controller for this
(http://ahref.in/8dc58) but I couldnt quite grasp the discussion
there.
Can Redbox be brought in here without too much trouble?
thanks again for you inputs!

On Apr 8, 1:46 pm, Ram <[email protected]> wrote:
> :) You were right. It was easy enough to use render :update and
> replace_html with :partial to accomplish it.
>
> I am however curious as to how we can do this using JSON. I started
> reading about JSON for another feature I needed but I realised I dint
> need JSON for it. I feel it would be a good exercise for me to
> implement it in tackling this problem. Could you explain a little bit
> more about the code you have shown me above or point me to where I can
> find the documentation explaining this? From what I remember, JSON is
> a format (Object Notation) to represent ActiveRecord objects (in
> Rails) for JS to handle. But setting the header, responseJSON et all
> is new to me.
>
> Thanks Fred!
>
> On Apr 8, 12:57 pm, Frederick Cheung <[email protected]>
> wrote:
>
> > On Apr 8, 8:38 am, Ram <[email protected]> wrote:
>
> > > 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?
>
> > I'm not sure this would be a problem - seems like a few calls to
> > page.replace_html 'info', :partial => 'blah' would do it in the other
> > cases.
>
> > > 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' %>
>
> > Nearly. your success callback gets 2 thigns: response and
> > responseJSON. responseJSON contains whatever JSON you put in the X-
> > JSON header of your response. You callback can be as simple as
>
> > check_for_redirect(json){
> >   if(json && json.redirect)
> >     page.location = json.redirect
>
> > }
>
> > and then pass :success => "check_for_redirect(responseJSON)". All you
> > need to do is to set that header appropriately if you want a redirect
> > to happen.
>
> > 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