Forum: Ruby on Rails No action from AJAX link_to_remote...

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
602f73f02a8b8abcf01ca093e1762006?d=identicon&s=25 Micah Bly (yak)
on 2006-02-28 04:45
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
1112c5cccf7d0cdcb1b1e615fff608f4?d=identicon&s=25 Feng Ji (Guest)
on 2006-02-28 05:14
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,
>
> Micah

Try to include the following

<head>
<%= javascript_include_tag :defaults %>
</head>

in your .rhtml file

-Feng
602f73f02a8b8abcf01ca093e1762006?d=identicon&s=25 Micah Bly (yak)
on 2006-02-28 05:50
Feng Ji wrote:

> <head>
> <%= javascript_include_tag :defaults %>
> </head>
>
> 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.
415a80eb88afdd18a5b776992ef9e12b?d=identicon&s=25 pmt (Guest)
on 2006-02-28 10:12
**render :layout => false** works at home =(
show_note.rhtml is used and not the main layout..

pmt
602f73f02a8b8abcf01ca093e1762006?d=identicon&s=25 Micah Bly (yak)
on 2006-02-28 19:54
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
This topic is locked and can not be replied to.