[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

How to change ruby's global variable through onclick event?

Vikas Gholap

1/22/2009 6:38:00 AM

Hello all,

I have problem that how to change ruby's global variable through onclick
event.?

my code is like in myvideo.html.erb file.
--------------------------------------------------------------------------
<a id='more_videos_link' class='ActionLink' href=\"#\"
onclick=\"something that change variable\">More videos</a>
--------------------------------------------------------------------
through onclick how can i change variable declared in my_controller.rb

-------------------------------------------------------
class myController < ApplicationController
$moreVideo = false

def moreVideo
$moreVideo = true
respond_to do |format|
format.html { render_partial 'home/video_search' }
end

end

end
--------------------------------------------------------------

is there way to change $moreVideo=true through onclick or href of anchor
tag given above.
--
Posted via http://www.ruby-....

2 Answers

Stefan Rusterholz

1/22/2009 9:44:00 AM

0

Vikas Gholap wrote:
> Hello all,
>
> I have problem that how to change ruby's global variable through onclick
> event.?
>
> my code is like in myvideo.html.erb file.
> --------------------------------------------------------------------------
> <a id='more_videos_link' class='ActionLink' href=\"#\"
> onclick=\"something that change variable\">More videos</a>
> --------------------------------------------------------------------
> through onclick how can i change variable declared in my_controller.rb
>
> -------------------------------------------------------
> class myController < ApplicationController
> $moreVideo = false
>
> def moreVideo
> $moreVideo = true
> respond_to do |format|
> format.html { render_partial 'home/video_search' }
> end
>
> end
>
> end
> --------------------------------------------------------------
>
> is there way to change $moreVideo=true through onclick or href of anchor
> tag given above.

Hi

You're probably better off in the rubyonrails mailing list instead of
the ruby ML.
However, a short answer anyway: to change values on the server side
(that's where your ruby code is) upon client side events (where there's
no executed ruby code anymore) you'll need a client side code such as
javascript e.g. using ajax to communicate that event to the server side.
On another note: you do NOT want a global variable there. A global will
be used not just for that single user but for all happening to be served
by the same instance of ruby.

Regards
Stefan
--
Posted via http://www.ruby-....

Brian Candler

1/22/2009 10:02:00 AM

0

Stefan Rusterholz wrote:
> On another note: you do NOT want a global variable there. A global will
> be used not just for that single user but for all happening to be served
> by the same instance of ruby.

And in most Rails deployments, there are multiple processes, so a global
variable changed in one will not affect another.

You probably want to change state in the *session*, which is accessible
to any process handling data on behalf of the same user.

session[:foo] = "bar"

(By default the session is stored in a cookie, so the total size is
limited to 4K. If you need to store more than this, select a different
session store model)
--
Posted via http://www.ruby-....