I wrote some code for adding a category to a list of categories on a page, complete with some rjs effects. The code saves the category alright but does not execute any js. I have to refresh to see any changes. Here is what I have been using: VIEW: list.html.erb <ul id = "category_list"> <%= render :partial => ''category'', :collection => @categories %> </ul> <% form_remote_tag :url => {:action => ''new''}, :html => {:id => ''category_form''} do %> Name: <%= text_field ''category'', ''name'' %> <%= submit_tag "Add" %> <% end %> CONTROLLER: category_controller.rb def new @category = Category.new(params[:category]) respond_to do |format| if @category.save format.js render :partial => ''category'', :object => @category end def list @categories = Category.find(:all) end RJS: new.js.erb page.insert_html :bottom, :category_list, :partial => ''category'', :object => @category page.visual_effect :highlight, "category_#{category.id}" page[:category_form].reset Has anyone else run into this issue or have any ideas about where I am going wrong? -- 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 -~----------~----~----~----~------~----~------~--~---
You can use the :collections parameter to render the list. I don''t see a need for new.js.erb. Use the :update=> parameter for the form tag to get the browser to refresh a section of the screen. Put your partial inside a <div> and pass the id of the <div> to the update parameter. You can do the highlights etc. as parameters to the form_remote_tag. Look at the documentation for form_remote_tag. On Apr 6, 4:24 am, Jack Kinsella <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> I wrote some code for adding a category to a list of categories on a > page, complete with some rjs effects. The code saves the category > alright but does not execute any js. I have to refresh to see any > changes. Here is what I have been using: > > VIEW: list.html.erb > > <ul id = "category_list"> > <%= render :partial => ''category'', :collection => @categories %> > </ul> > > <% form_remote_tag :url => {:action => ''new''}, > :html => {:id => ''category_form''} do %> > Name: <%= text_field ''category'', ''name'' %> > <%= submit_tag "Add" %> > <% end %> > > CONTROLLER: category_controller.rb > > def new > @category = Category.new(params[:category]) > respond_to do |format| > if @category.save > format.js > render :partial => ''category'', :object => @category > end > > def list > @categories = Category.find(:all) > end > > RJS: new.js.erb > > page.insert_html :bottom, :category_list, :partial => ''category'', > :object => @category > page.visual_effect :highlight, "category_#{category.id}" > page[:category_form].reset > > Has anyone else run into this issue or have any ideas about where I am > going wrong? > -- > Posted viahttp://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 -~----------~----~----~----~------~----~------~--~---
On 6 Apr 2008, at 00:24, Jack Kinsella wrote:> > > I wrote some code for adding a category to a list of categories on a > page, complete with some rjs effects. The code saves the category > alright but does not execute any js. I have to refresh to see any > changes. Here is what I have been using: > > > VIEW: list.html.erb > > <ul id = "category_list"> > <%= render :partial => ''category'', :collection => @categories %> > </ul> > > <% form_remote_tag :url => {:action => ''new''}, > :html => {:id => ''category_form''} do %> > Name: <%= text_field ''category'', ''name'' %> > <%= submit_tag "Add" %> > <% end %> > > CONTROLLER: category_controller.rb > > def new > @category = Category.new(params[:category]) > respond_to do |format| > if @category.save > format.js > render :partial => ''category'', :object => @category > end > > def list > @categories = Category.find(:all) > end >This can''t be exactly what''s in your controller because it''s syntatically incorrect. But I''d guess that your new.js.erb file is never exececuted, since you''re telling it to render the partial instead. On top of that it should be called new.js.rjs, not new.js.erb Fred> > RJS: new.js.erb > > page.insert_html :bottom, :category_list, :partial => ''category'', > :object => @category > page.visual_effect :highlight, "category_#{category.id}" > page[:category_form].reset > > > Has anyone else run into this issue or have any ideas about where I am > going wrong? > -- > 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 finally got it working. Many thanks to Fred and Mukund. I changed two things: Firstly instead of putting the div id into an unordered list I made a separate div tag. Secondly I got rid of the render partial line in the controller. -- 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 -~----------~----~----~----~------~----~------~--~---