No action from AJAX link_to_remote


#1

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:
Notes

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:

*should show up here*

That part is visible, but the text never gets replaced. I’ve tried with
Camino and Safari so far.

Thanks in advance,

Micah


#2

Micah B. 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:
Notes

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:

*should show up here*

That part is visible, but the text never gets replaced. I’ve tried with
Camino and Safari so far.

Thanks in advance,

Micah

Try to include the following

<%= javascript_include_tag :defaults %>

in your .rhtml file

-Feng


#3

Feng Ji wrote:

<%= javascript_include_tag :defaults %>

in your .rhtml file

Feng, 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.


#4

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.

  1. 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


#5

render :layout => false works at home =(
show_note.rhtml is used and not the main layout…

pmt