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

V

Vikas Gholap

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
 
S

Stefan Rusterholz

Vikas said:
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

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
 
B

Brian Candler

Stefan said:
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)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top