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
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
On Jul 11, 5:09 am, JannaB <mistressja...-PkbjNfxxIARBDgjK7y7TUQ@public.gmane.org> 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> 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
Fred, I put the whole div with the link_to_remote''s in it''s
own
partial:
<div id="buttonrak1">
<% 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 %>
</div>
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
[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
On Jul 11, 3:56 pm, JannaB <mistressja...-PkbjNfxxIARBDgjK7y7TUQ@public.gmane.org> wrote:> Fred, I put the whole div with the link_to_remote''s in it''s own > partial: > > <div id="buttonrak1"> > <% 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> %> > <% 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 %> > </div> > > 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
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