AJAX & Ruby & Rails newbie here. I''ve got a link to remote that I believe should be working, but doesn''t seem in fact to do *anything*. I''m looking at the webrick log, since the Book says I should be seeing some hot POST action in there, but there''s literally no change when I click on the JS link. From looking at the source that''s generate, it seems like it should work. If I take the link it generates there out and put it in the address bar, it works fine. Here''s the code: link_to_remote(image_tag("/images/notes3.png", :size => "28x30", :alt => "Notes", :border => "0"), :update => "note#{project.id}", :url => { :action => :show_note, :id => project.id }) Here''s the resulting JS: <a href="#" onclick="new Ajax.Updater(''note1'', ''/project/show_note/1'', {asynchronous:true, evalScripts:true}); return false;"><img alt="Notes" border="0" height="30" src="/images/notes3.png" width="28" /></a> I don''t think that :show_note is even being hit (but I''m not sure how to check that). The HTML where this should go to is: <div id="note<%= project.id -%>">*should show up here*</div> That part is visible, but the text never gets replaced. I''ve tried with Camino and Safari so far. Thanks in advance, Micah -- Posted via http://www.ruby-forum.com/.
Micah Bly wrote:> AJAX & Ruby & Rails newbie here. > > I''ve got a link to remote that I believe should be working, but doesn''t > seem in fact to do *anything*. I''m looking at the webrick log, since > the Book says I should be seeing some hot POST action in there, but > there''s literally no change when I click on the JS link. From looking at > the source that''s generate, it seems like it should work. If I take the > link it generates there out and put it in the address bar, it works > fine. > > Here''s the code: > link_to_remote(image_tag("/images/notes3.png", :size => "28x30", :alt => > "Notes", :border => "0"), :update => "note#{project.id}", :url => { > :action => :show_note, :id => project.id }) > > Here''s the resulting JS: > <a href="#" onclick="new Ajax.Updater(''note1'', ''/project/show_note/1'', > {asynchronous:true, evalScripts:true}); return false;"><img alt="Notes" > border="0" height="30" src="/images/notes3.png" width="28" /></a> > > I don''t think that :show_note is even being hit (but I''m not sure how to > check that). > > The HTML where this should go to is: > <div id="note<%= project.id -%>">*should show up here*</div> > > That part is visible, but the text never gets replaced. I''ve tried with > Camino and Safari so far. > > Thanks in advance, > > MicahTry to include the following <head> <%= javascript_include_tag :defaults %> </head> in your .rhtml file -Feng -- Posted via http://www.ruby-forum.com/.
Feng Ji wrote:> <head> > <%= javascript_include_tag :defaults %> > </head> > > in your .rhtml fileFeng, thanks! That just works. Now if I could just figure out why the damn layout keeps re-rendering itself. I have tried about 10 combinations to try and stop it with no luck: def show_note @notes = self.project_notes #render(:layout => false) #render :layout => false #render(:partial => "show_note", :collection => @notes) #render :partial => "/show_note" render :action => "show_note", :layout => false end no errors in any of those, but none of them make any difference at all. -- Posted via http://www.ruby-forum.com/.
**render :layout => false** works at home =( show_note.rhtml is used and not the main layout.. pmt -- Posted via http://www.ruby-forum.com/.
pmt wrote:> **render :layout => false** works at home =( > show_note.rhtml is used and not the main layout..This was very strange. I still don''t know what''s going on. It works now, but I had to change things. 1) it turns out with the link_to_remote code above, the Project.show_note method was never getting called at all. It was going right to the show_note.rhtml file (I assume that''s known, but the impression I got from the book example is that this would be going to a method (hence the render: bit). So I just made show_note.rhmtl into a shell, with this only: <%= render :partial => ''show_note'' %> And took the guts of it and put it into "_show_note.rhtml". This works fine, it doesn''t render the layout again. 2) if I tried to change the link_to_remote so that instead of :show_note, the action was project.show_note, that DID call the project show_note method. Unfortunately, it didn''t seem to pass the ID to it, and also, all the "render" calls I tried came up as unknown methods or something. So I gave up on that for now. I think I want a whole Rails book on just AJAX<>Rails. Micah -- Posted via http://www.ruby-forum.com/.