I allow users to dynamically add and remove phone numbers with Ajax. They can then mark the primary number by clicking on a star which triggers an Ajax method to update the primary number.
That method calls an RJS template that I need to modify the newly selected star as primary by changing its image to be star.gif & making the other images become star_off.gif.
I am able to get the star image updating working partially, but I am not sure how to pass the index parameter to my RJS call so that everything will stay numbered correctly in my array.
I am also not sure how to go about converting all non-primary images (including the previous primary) to be star_off while leaving the new primary as star_on.
Relevant code below. Help is appreciated. Thanks!
_star.rhtml
<%= link_to_remote "#{star_image(phone, index)}", :url => {:controller => 'contacts', :action =>'mark_as_primary_phone', :id => phone, :index => index} %>
mark_as_primary.rjs
page.replace 'phone_off', :partial => "/shared/star", :locals => { :phone => @phone}