# Conditional link\_to\_remote not re-rendering

**URL:** <https://www.ruby-forum.com/t/conditional-link-to-remote-not-re-rendering/171901>\
**Category:** Rails\
**Created:** [July 11, 2009, 3:03am UTC](https://www.ruby-forum.com/t/conditional-link-to-remote-not-re-rendering/171901 "2009-07-11T03:03:08Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![mistressjanna](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/3ab097/32.png) [@mistressjanna](https://www.ruby-forum.com/u/mistressjanna)\
**Post date:** [July 11, 2009, 3:03am UTC](https://www.ruby-forum.com/t/conditional-link-to-remote-not-re-rendering/171901/1 "2009-07-11T03:03:08Z")

</div>

I have an int, ‘floorfrozen,’ in my table, ‘channels’ that can take a  
value of 0 or 1.

When I render a page, an image in a link\_to\_remote is called  
differently depending what the value of channel.floorfrozen is, in a  
partial, as follows:

\<% if @channel.floorfrozen %\>  
\<%= link\_to\_remote image\_tag("/images/icecube.gif"), {:url =\>  
{:controller =\> ‘channels’,:action =\> ‘freezer’}},:title =\> ‘Unfreeze  
the floor’, :type =\> “submit”,:style =\> “float: right; border-style:  
groove; padding: 1px;” %\>  
\<% else %\>  
\<%= link\_to\_remote image\_tag("/images/icecube.gif"), {:url =\>  
{:controller =\> ‘channels’,:action =\> ‘freezer’}},:title =\> ‘Freeze  
the floor’, :type =\> “submit”,:style =\> “float: right; border-style:  
ridge; padding: 1px;” %\>  
\<% end %\>

The problem is that the image remains the same! The functionality of  
what is occuring in the the controller action, channel.freezer, is  
correct, but the link\_to\_remote never rerenders UNLESS I refresh the  
page. Can somene tell me why this is and how I can fix it so that my  
page renders properly? Thanks, Janna B.

def freezer  
if @channel.floorfrozen == 0  
@channel.update\_attributes(:floorfrozen =\> 1)  
@channel.floorfrozen = 1  
else  
@channel.update\_attributes(:floorfrozen =\> 0)  
@channel.floorfrozen = 0  
end  
render :action =\> ‘display’  
end

---

<div class="post-metadata">

**Author:** ![mistressjanna](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/3ab097/32.png) [@mistressjanna](https://www.ruby-forum.com/u/mistressjanna)\
**Post date:** [July 11, 2009, 6:10am UTC](https://www.ruby-forum.com/t/conditional-link-to-remote-not-re-rendering/171901/2 "2009-07-11T06:10:02Z")

</div>

I’m stumped here – well aware that link\_to\_remote is intended to do  
something other than what I am trying to use it for. You see, I need  
to create a sort of button, that takes an image and that has different  
looks (css styles, depending upon the state of a variable), that works  
without rendering a page.

God. Does anyone know any way I can accomplish this? It SEEMS like it  
is easiest solved as a rails solution because of the Ajax helpers  
inherint in Rails – but I am open to anything! -Janna B

---

<div class="post-metadata">

**Author:** ![mistressjanna](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/3ab097/32.png) [@mistressjanna](https://www.ruby-forum.com/u/mistressjanna)\
**Post date:** [July 11, 2009, 12:16pm UTC](https://www.ruby-forum.com/t/conditional-link-to-remote-not-re-rendering/171901/3 "2009-07-11T12:16:51Z")

</div>

On Jul 11, 5:09 am, JannaB [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I’m stumped here – well aware that link\_to\_remote is intended to do  
> something other than what I am trying to use it for. You see, I need  
> to create a sort of button, that takes an image and that has different  
> looks (css styles, depending upon the state of a variable), that works  
> without rendering a page.

Well you’re calling render in your action but you haven’t told  
link\_to\_remote what it should do with the html that is rendered so it  
just dumps it on the floor. (Have a look at link\_to\_remote’s :update  
option)

Fred

---

<div class="post-metadata">

**Author:** ![mistressjanna](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/3ab097/32.png) [@mistressjanna](https://www.ruby-forum.com/u/mistressjanna)\
**Post date:** [July 11, 2009, 4:56pm UTC](https://www.ruby-forum.com/t/conditional-link-to-remote-not-re-rendering/171901/4 "2009-07-11T16:56:39Z")

</div>

Fred, I put the whole div with the link\_to\_remote’s in it’s own  
partial:

\<% if @channel.floorfrozen != 0 %\> \<%= link\_to\_remote image\_tag("/images/icecube.gif"), {:url =\> {:controller =\> 'channels',:action =\> 'freezer', :update =\> 'buttonrak1'}},:title =\> 'Unfreeze the floor', :type =\> "submit",:style =\> "float: right; border-style: groove; padding: 1px;" %\> \<% else %\> \<%= link\_to\_remote image\_tag("/images/icecube.gif"), {:url =\> {:controller =\> 'channels',:action =\> 'freezer', :update =\> 'buttonrak1'}},:title =\> 'Freeze the floor', :type =\> "submit",:style =\> "float: right; border-style: ridge; padding: 1px;" %\> \<% end %\>

Then, in my controller, I re-render the partial (i.e. the div with the  
link\_to\_remotes):

def freezer  
###blah blah  
render :partial =\> ‘brack1partial’  
end

---

<div class="post-metadata">

**Author:** ![mistressjanna](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/3ab097/32.png) [@mistressjanna](https://www.ruby-forum.com/u/mistressjanna)\
**Post date:** [July 11, 2009, 6:26pm UTC](https://www.ruby-forum.com/t/conditional-link-to-remote-not-re-rendering/171901/5 "2009-07-11T18:26:04Z")

</div>

On Jul 11, 3:56 pm, JannaB [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Fred, I put the whole div with the link\_to\_remote’s in it’s own  
> partial:
> 
> \<% if @channel.floorfrozen != 0 %\> \<%= link\_to\_remote image\_tag("/images/icecube.gif"), {:url =\> {:controller =\> 'channels',:action =\> 'freezer', :update =\> 'buttonrak1'}},:title =\> 'Unfreeze the floor', :type =\> "submit",:style =\> "float: right; border-style: groove; padding: 1px;"

You’ve put the update in the hash of url options, which you shouldn’t  
do.  
It should be link\_to\_remote ‘blah’, {:url =\> {…}, :update =\>  
“…”}, html\_options

Fred

---

<div class="post-metadata">

**Author:** ![mistressjanna](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/3ab097/32.png) [@mistressjanna](https://www.ruby-forum.com/u/mistressjanna)\
**Post date:** [July 11, 2009, 4:58pm UTC](https://www.ruby-forum.com/t/conditional-link-to-remote-not-re-rendering/171901/6 "2009-07-11T16:58:24Z")

</div>

[Do not hit {tab} while attempting to post!]

…continuing, the point is, it does NOT rerender that partial / div  
even though the controller code is being executed properly. Isn;t this  
the way I should do something though for link\_to\_remote when what I  
want to update contains the html portion that calls it? -Janna B

---

<div class="post-metadata">

**Author:** ![mistressjanna](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/3ab097/32.png) [@mistressjanna](https://www.ruby-forum.com/u/mistressjanna)\
**Post date:** [July 11, 2009, 6:54pm UTC](https://www.ruby-forum.com/t/conditional-link-to-remote-not-re-rendering/171901/7 "2009-07-11T18:54:43Z")

</div>

You know…your sharing of your knowledge on here…I can read all  
day long on Ruby, and I can write code all day long – but when you  
(and a few others on this list as well) point out what should be  
obvious (errors) to me, it REALLY sinks in, and my understanding of  
this grows exponentially, and I am obligated in the future to  
contribute to others questions as my knowledge level increases.

I really cannot thank you – and the others here who help, enough. -  
Janna B
