# No action from AJAX link\_to\_remote

**URL:** <https://www.ruby-forum.com/t/no-action-from-ajax-link-to-remote/74511>\
**Category:** Rails\
**Created:** [February 28, 2006, 4:45am UTC](https://www.ruby-forum.com/t/no-action-from-ajax-link-to-remote/74511 "2006-02-28T04:45:02Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![yak](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/b3f665/32.png) [@yak](https://www.ruby-forum.com/u/yak)\
**Post date:** [February 28, 2006, 4:45am UTC](https://www.ruby-forum.com/t/no-action-from-ajax-link-to-remote/74511/1 "2006-02-28T04:45:02Z")

</div>

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](https://test.ruby-forum.com/images/notes3.png)

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

---

<div class="post-metadata">

**Author:** ![yak](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/b3f665/32.png) [@yak](https://www.ruby-forum.com/u/yak)\
**Post date:** [February 28, 2006, 5:14am UTC](https://www.ruby-forum.com/t/no-action-from-ajax-link-to-remote/74511/2 "2006-02-28T05:14:34Z")

</div>

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](https://www.ruby-forum.com/images/notes3.png)
> 
> 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

---

<div class="post-metadata">

**Author:** ![yak](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/b3f665/32.png) [@yak](https://www.ruby-forum.com/u/yak)\
**Post date:** [February 28, 2006, 5:50am UTC](https://www.ruby-forum.com/t/no-action-from-ajax-link-to-remote/74511/3 "2006-02-28T05:50:26Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![yak](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/b3f665/32.png) [@yak](https://www.ruby-forum.com/u/yak)\
**Post date:** [February 28, 2006, 7:54pm UTC](https://www.ruby-forum.com/t/no-action-from-ajax-link-to-remote/74511/4 "2006-02-28T19:54:49Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![yak](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/b3f665/32.png) [@yak](https://www.ruby-forum.com/u/yak)\
**Post date:** [February 28, 2006, 10:12am UTC](https://www.ruby-forum.com/t/no-action-from-ajax-link-to-remote/74511/5 "2006-02-28T10:12:00Z")

</div>

**render :layout =\> false** works at home =(  
show\_note.rhtml is used and not the main layout…

pmt
