So I''m trying to re-factor some controller code with over 20 rjs templates (that all do the same thing, but for different methods). My original code is pretty straightforward. I just create an object then re-render a couple partials. Controller: def input_event @person = Person.find(params[:id]) event = Event.new(params[:event]) if event.save return if request.xhr? render :partial => ''events'' render :partial => ''inputs'' end end input_event.rjs page.replace_html("event_list", :partial => "events", :object => @person) page.replace_html("input_list", :partial => "inputs", :object => @person) After browsing around, there appear to be two methods of re-factoring to inline rjs. The first is to throw the contents of the rjs file directly into the controller method like this: def input_event @person = Person.find(params[:id]) event = Event.new(params[:event]) if event.save return if request.xhr? render :update do |page| page.replace_html("event_list", :partial => "events", :object => @person) page.replace_html("input_list", :partial => "inputs", :object => @person) end end end The second method is to create a method in the corresponding helper module to handle the rjs. This would be more attractive since I could use this same method for my 20+ controller methods. Controller def input_event @person = Person.find(params[:id]) event = Event.new(params[:event]) if event.save return if request.xhr? render(:update){|page| page.input(@person)} end end Controller Helper def input(person) page.replace_html("event_list", :partial => "events", :object => person) page.replace_html("input_list", :partial => "inputs", :object => person) end However, I can''t get either of these inline methods to work. Is there anything else I need to change? Thanks, Peter -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
> > > def input_event > @person = Person.find(params[:id]) > event = Event.new(params[:event]) > if event.save > return if request.xhr? > render(:update){|page| page.input(@person)} > end > end > > Controller Helper > > def input(person) > page.replace_html("event_list", :partial => "events", :object => > person) > page.replace_html("input_list", :partial => "inputs", :object => > person) > end > > However, I can''t get either of these inline methods to work. Is there > anything else I need to change?I saw a technique at railsconf europe last year, which (if I remember correctly) went something along the lines of def input update_page do |page| page.replace_html("event_list", :partial => "events", :object =>person) page.replace_html("input_list", :partial => "inputs", :object =>person) end end render :update do |page| page << input end 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
> However, I can''t get either of these inline methods to work. Is there > anything else I need to change?what does "can''t get ... to work" exactly mean? - methods are not called? - get errors? - browser renders strange things? -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Fred - That didn''t work as is, but I''ll dig around for what you saw at rails conf eu. Thanks regardless. Thorsten - Sorry for being vague. By can''t get to work, I mean the controller method executes without any errors and creates the ''event'' object, but the ''events'' and ''inputs'' partials don''t re-render like they do when I use a separate rjs template. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
could be: on the view site there are two ways to trigger ajax calls: use the :update => or not using it. if you use it (eg: :update => ''my_id''), every ajax response will be rendered in the tag with ''my_id'' for inline-rjs you give the target-tag with every command like page.replace_html("input_list"... to replace ''input_list''. in this case you must not use :update -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Thorsten Mueller wrote:> could be: > on the view site there are two ways to trigger ajax calls: > > use the :update => > or not using it. if you use it (eg: :update => ''my_id''), every ajax > response will be rendered in the tag with ''my_id'' > for inline-rjs you give the target-tag with every command like > page.replace_html("input_list"... > to replace ''input_list''. in this case you must not use :updateSo with the commands I have: page.replace_html("event_list", :partial => "events", :object => @person) page.replace_html("input_list", :partial => "inputs", :object => @person) I''m giving a target-tag to these page elements: <ul id=''event_list''><%= render :partial => ''events'', :object => @claimant %></ul> <ul id=''input_list''><%= render :partial => ''inputs'', :object => @claimant %></ul> Right? So therefore I should not use :update? What would I put in the place of :update for these lines then? render :update do |page| render(:update){|page| page.input(@person)} -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Peter Marks wrote:> <ul id=''event_list''><%= render :partial => ''events'', :object => > @claimant %></ul> > <ul id=''input_list''><%= render :partial => ''inputs'', :object => > @claimant %></ul>Should read: <ul id=''event_list''><%= render :partial => ''events'', :object => @person %></ul> <ul id=''input_list''><%= render :partial => ''inputs'', :object => @person %></ul> -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
> > I''m giving a target-tag to these page elements: > > <ul id=''event_list''><%= render :partial => ''events'', :object => > @claimant %></ul> > <ul id=''input_list''><%= render :partial => ''inputs'', :object => > @claimant %></ul> > > Right? >right> So therefore I should not use :update? What would I put in the place of > :update for these lines then? > > render :update do |page| > render(:update){|page| page.input(@person)}sorry, i wasn''t clear. in the controller that''s ok, but in the view you (may) have a link to the remote action like that: link_to_remote "Delete this post", :url => { :action => "destroy", :id => post.id }, :update => "posts" and here you would omit the :update => "posts" -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Thorsten Mueller wrote:> sorry, i wasn''t clear. in the controller that''s ok, but in the view you > (may) have a link to the remote action like that: > > link_to_remote "Delete this post", > :url => { :action => "destroy", :id => post.id }, > :update => "posts" > > and here you would omit the > > :update => "posts"I see what you''re saying now. I''m not using :update in my method call though: <% form_remote_tag :url => {:action => ''input_event'', :id => @person } do %> (form) <%= submit_tag ''Enter'' %> So I guess something else is going wrong. Thanks regardless :) -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Looks like removing "return if request.xhr?" took care of this one. Strange. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---