OK, I used the ID of the select and did a replace:

RJS:
page[:showcontact].hide
page[:contactlist].show
page.insert_html :bottom,'contactlist',  :partial => 'ajaxAddToMop', :locals
=> {:contact => @contact }
page[:contact_id].replace :partial => "updateContactList", :locals =>
{:contacts => @contacts, :mop => @mop }

 Partial:

<%= select('contact', 'id', @contacts, {:prompt => 'Select Contact'} ,{
:onchange => remote_function(:url => {     :controller => 'contacts',
:action => "ajaxshowcontact", :id => @mop.id},



:with => "'contactid=' + this.value" )
} ) %>


No change.  Prompt is still not showing up.  Data is there jsut not he
prompt.  I need the prompt as I use an ajax on change so the user can
view/edit/update the user info if necessary inside the form.  the controller
code basically is updating the contact lsit.

1.Gets all contacts.
2. gets all contacts associated with the form
3. subtracts the two and givesme an array with the contacts not associated
woit the form.
4.  As I add users to the form I make the association to the form.  This way
I can update the list easier than keeping track of an array.

Here is the controller code, no real significance.

def ajaxAddToMop
    @contact = Contact.find(params[:contact][:id], :include => [:company])
        @mop = Mop.find(params[:id])
        @mop.contacts << @contact
        a = Contact.all.collect{|p| [ p.id ] }
        b = @mop.contacts.all.collect{|p| [ p.id ] }
        c = a-b
        ar = Array.new
        c.each{|arr|
            arr.each{|p|
                ar << p
            }
        }

        @contacts = Contact.find(:all, :conditions => ["id IN (?)",
ar]).collect {|p| [ p.name, p.id ] }
  end


On Sat, Apr 11, 2009 at 11:42 AM, Jaryl Sim <quantum.crus...@gmail.com>wrote:

>
> Hmm, hope you can post up more code, even from your controller as
> well.
>
> I think that instead of replacing the entire select tag, you can
> simply replace its contents. Firstly, give the select tag an id so
> that in your RJS, you can replace_html with options_for_select or
> whatever function you might want to use.
>
> On Apr 11, 8:01 am, Chris Habgood <chabg...@gmail.com> wrote:
> > Ok, that select I put is the only thing in the partial.
> > Here is the rjs:
> > page[:contact_list].replace_html :partial => 'updateContactList', :locals
> =>
> > { :contact => @contact }
> >
> > On Fri, Apr 10, 2009 at 6:58 PM, Phlip <phlip2...@gmail.com> wrote:
> >
> > > Me wrote:
> > > > I have this select in a form:
> > > > <%= select('contact', 'id', @contacts, {:prompt => 'Select Contact'}
> ,
> > > > { :onchange => remote_function(:url => {      :controller =>
> > > > 'contacts', :action => "ajaxshowcontact", :id => @mop.id}, :with =>
> > > > "'contactid=' + this.value" )
> > > > } ) %>
> >
> > > > The prompt works in the form but when I do a replace_html on it I get
> > > > everything but the prompt.
> >
> > > Post the replace_html code?
> >
> > > Next, put only that <%= select %> thing into a partial (yes tiny
> otherwise
> > > useless partials are a Best Practice), then do rjs.replace_html
> :my_div,
> > > :partial => 'my_partial'. (I call "rjs" the variable everyone else
> calls
> > > "page",
> > > because the interthing has too many "page" variables all over it!)
> >
> > > You could also see about putting the :url into a named route. Just
> about
> > > anything in Rails that's "named" is a best practice, too!
> >
> >
> >
>

--~--~---------~--~----~------------~-------~--~----~
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 rubyonrails-talk@googlegroups.com
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to