# Problem with link\_to\_remote/render\_partial and :html

**URL:** <https://www.ruby-forum.com/t/problem-with-link-to-remote-render-partial-and-html/70214>\
**Category:** Rails\
**Created:** [September 27, 2006, 3:24pm UTC](https://www.ruby-forum.com/t/problem-with-link-to-remote-render-partial-and-html/70214 "2006-09-27T15:24:42Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![leoncelot](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/58f4c7/32.png) [@leoncelot](https://www.ruby-forum.com/u/leoncelot)\
**Post date:** [September 27, 2006, 3:24pm UTC](https://www.ruby-forum.com/t/problem-with-link-to-remote-render-partial-and-html/70214/1 "2006-09-27T15:24:42Z")

</div>

I have the following code in my view:

 Ajax Demo \<%= javascript\_include\_tag "prototype" %\> \<%= javascript\_include\_tag :defaults %\> 
 This will go away 
 \<%= link\_to\_remote "Do Magic", :url =\> { :action =\> "DoMagic" }, :complete =\> visual\_effect(:fade, "myDiv", :duration =\> 1.5), :html =\> {:style=\>"background-color: #0e0;"} %\> 

And this in my controller:

class DemoController \< ApplicationController

def index  
end

def DoMagic  
render\_partial false  
end

end

The problem I’m having is twofold:

1. First, no matter where I place my :html=\>{} settings or what I put in  
it, it gets ignored. The style is never applied.
2. Using Firebog to watch my AJAX request I see that I keep getting an  
error back, even though it works in the end. Here is the error I see  
coming back in Firebug: NoMethodError in DemoController#DoMagic

- Now I’ve tried using “render\_partial false”, “render(:partial=\>false”,  
etc. but nothing works to get rid of this error message.

Note: I know this is a trivial example and that my remote call does  
nothing, I just wanted to get this working first so I could add my logic  
later.

Thanks for your help.

---

<div class="post-metadata">

**Author:** ![leoncelot](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/58f4c7/32.png) [@leoncelot](https://www.ruby-forum.com/u/leoncelot)\
**Post date:** [September 27, 2006, 4:11pm UTC](https://www.ruby-forum.com/t/problem-with-link-to-remote-render-partial-and-html/70214/2 "2006-09-27T16:11:02Z")

</div>

first off, the javascript\_include\_tag for prototype is redundant, as  
prototype is included in the defaults.

second, try this

This will go away
\<%= link\_to\_remote "Do Magic", :url =\> {:action =\> "DoMagic"}) -%\>

then in your controller:

def DoMagic  
render :update do |page|  
page.visual\_effect :fade, ‘my\_div’, :duration =\> 1.5  
end  
end

your browser will make an ajax request when the link is clicked, the  
server will respond with some javascript which will be evaulated and  
your div should fade out.

---

<div class="post-metadata">

**Author:** ![leoncelot](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/58f4c7/32.png) [@leoncelot](https://www.ruby-forum.com/u/leoncelot)\
**Post date:** [September 27, 2006, 4:38pm UTC](https://www.ruby-forum.com/t/problem-with-link-to-remote-render-partial-and-html/70214/3 "2006-09-27T16:38:44Z")

</div>

Chris H. wrote:

> first off, the javascript\_include\_tag for prototype is redundant, as  
> prototype is included in the defaults.
> 
> second, try this

Thanks a bunch! It’s working now without the error. The only issue I  
have left is trying to apply my CSS style to the link\_to\_remote.

---

<div class="post-metadata">

**Author:** ![leoncelot](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/58f4c7/32.png) [@leoncelot](https://www.ruby-forum.com/u/leoncelot)\
**Post date:** [September 27, 2006, 7:35pm UTC](https://www.ruby-forum.com/t/problem-with-link-to-remote-render-partial-and-html/70214/4 "2006-09-27T19:35:37Z")

</div>

link\_to\_remote has three parameters, last two of which is a hash.

[http://rubyonrails.org/api/classes/ActionView/Helpers/PrototypeHelper.html#M000412](http://rubyonrails.org/api/classes/ActionView/Helpers/PrototypeHelper.html#M000412)

So do this:

\<%= link\_to\_remote(“Do Magic”, { :url =\> { :action =\> “DoMagic” } },  
{:style=\>“background-color: #0e0;”}) %\>

(last parameter is the html\_options)

Vish
