Cayce Balara
2006-Aug-12 17:51 UTC
[Rails] In place editing on a list - not passing ID through
I want to do in-place edits on a list of data, but I''m having trouble getting the ID passed through to the controller. I use this in my view to create the field: <% for frame in @frames %> ... <%= in_place_editor_field :frame, :price %> <% end %> and this produces the following in my output: <span class="in_place_editor_field" id="frame_price__in_place_editor">0.0</span> <script type="text/javascript"> //<![CDATA[ new Ajax.InPlaceEditor(''frame_price__in_place_editor'', ''/frames/set_frame_price'') //]]> </script> I understand from some research that what I''m after is to replace "frame_price__in_place_editor" in both places with "frame_price_xx_in_place_editor", where "xx" is the id of the item to be updated, but I cannot figure out how to modify the call to in_place_editor_field to pass the id in. I''ve tried the following with no luck... <%= in_place_editor_field :frame, :price, :id => frame %> <%= in_place_editor_field :frame, :price, :id => frame.id %> <%= in_place_editor_field :frame, :price, {:id => frame} %> <%= in_place_editor_field :frame, :price, {:id => frame.id} %> I''d appreciate any help. yb -- Posted via http://www.ruby-forum.com/.
Cayce Balara
2006-Aug-12 17:54 UTC
[Rails] Re: In place editing on a list - not passing ID through
Have since discovered that I also need the URL in the Ajax call to include the id of the item to be updated, as such: <script type="text/javascript"> //<![CDATA[ new Ajax.InPlaceEditor(''frame_price_xx_in_place_editor'', ''/frames/set_frame_price/xx'') //]]> ...where "xx" is the id of the item to be updated. Still having no luck. thanks. yb. -- Posted via http://www.ruby-forum.com/.
Cayce Balara
2006-Aug-12 18:11 UTC
[Rails] Re: In place editing on a list - not passing ID through
I have since changed view code to the following... <%=in_place_editor_field (:frame, :price, {:id => "frame_price_#{frame.id}_in_place_editor"}, {:url => "/frames/set_frame_price/#{frame.id}"}) %> ...and this appears to be accomplishing what I''m after, but seems extremely kludge-y. Still wondering if there is a better way of doing this? thanks. yb. -- Posted via http://www.ruby-forum.com/.
gustav Paul
2006-Aug-12 19:17 UTC
[Rails] Re: In place editing on a list - not passing ID through
gustav Paul wrote:> Cayce Balara wrote: >> I have since changed view code to the following... >> >> <%=in_place_editor_field (:frame, :price, {:id => >> "frame_price_#{frame.id}_in_place_editor"}, {:url => >> "/frames/set_frame_price/#{frame.id}"}) %> >> >> ...and this appears to be accomplishing what I''m after, but seems >> extremely kludge-y. >> >> Still wondering if there is a better way of doing this? >> >> thanks. >> yb. > <%@frames.each do |frame|%> > <span id="price_<%=frame.id%>"><%=frame.price%></span> > <%=in_place_editor("price_#{frame.id}", > {:url => "/frames/set_frame_price/#{frame.id}"})%> > <%end%> > > In the controller: > > def set_frame_price > frame = Frame.find(params[:id]) > frame.price = params[:value] > frame.save > render :text => frame.price > #i put a return in here once...baaaaaad results :] > end > > Hope this works > > Ciao > Gustav Paul > gustav@rails.co.za > itsdEx.comI think the in_place_editor_field helper works if you''ve only got one, in a list you need to somehow tell the different ones apart...one way is to use their ids Gustav Paul -- Posted via http://www.ruby-forum.com/.
gustav Paul
2006-Aug-12 19:18 UTC
[Rails] Re: In place editing on a list - not passing ID through
Cayce Balara wrote:> I have since changed view code to the following... > > <%=in_place_editor_field (:frame, :price, {:id => > "frame_price_#{frame.id}_in_place_editor"}, {:url => > "/frames/set_frame_price/#{frame.id}"}) %> > > ...and this appears to be accomplishing what I''m after, but seems > extremely kludge-y. > > Still wondering if there is a better way of doing this? > > thanks. > yb.<%@frames.each do |frame|%> <span id="price_<%=frame.id%>"><%=frame.price%></span> <%=in_place_editor("price_#{frame.id}", {:url => "/frames/set_frame_price/#{frame.id}"})%> <%end%> In the controller: def set_frame_price frame = Frame.find(params[:id]) frame.price = params[:value] frame.save render :text => frame.price #i put a return in here once...baaaaaad results :] end Hope this works Ciao Gustav Paul gustav@rails.co.za itsdEx.com -- Posted via http://www.ruby-forum.com/.