# Reloading a div with a changed session variable

**URL:** <https://www.ruby-forum.com/t/reloading-a-div-with-a-changed-session-variable/104500>\
**Category:** Rails\
**Created:** [May 18, 2007, 7:01pm UTC](https://www.ruby-forum.com/t/reloading-a-div-with-a-changed-session-variable/104500 "2007-05-18T19:01:43Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![d2kagw](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/b5a626/32.png) [@d2kagw](https://www.ruby-forum.com/u/d2kagw)\
**Post date:** [May 18, 2007, 7:01pm UTC](https://www.ruby-forum.com/t/reloading-a-div-with-a-changed-session-variable/104500/1 "2007-05-18T19:01:43Z")

</div>

New to this, so bear with me.

Controller:

def show  
@client = Client.find\_by\_permalink(params[:permalink])  
@images = ClientImage.find\_all\_by\_client\_id(@client, :order =\> “id  
ASC”)  
session[:client] = @client  
if session[:image].blank?  
session[:image] = @images[0]  
end  
end

def view\_image  
@image = ClientImage.find\_by\_id(params[:id])  
session[:image] = @image  
end

View:

\<%= image\_tag url\_for\_file\_column(session[:image], “image”), :alt =\>  
@client.name %\>

RJS:

page[:content\_top].reload

I thought that reloading the div after changing the session variable out  
would cause a new image to display, but it does nothing.

---

<div class="post-metadata">

**Author:** ![d2kagw](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/b5a626/32.png) [@d2kagw](https://www.ruby-forum.com/u/d2kagw)\
**Post date:** [May 18, 2007, 8:46pm UTC](https://www.ruby-forum.com/t/reloading-a-div-with-a-changed-session-variable/104500/2 "2007-05-18T20:46:06Z")

</div>

What button/link are you hitting that you want to reload the page  
with? What is the name of the function? What is the name of the  
view? What is the name of the controller? What is the name of the  
RJS file? Are you passing in info from the app to reload it?

On 5/18/07, Aaron W. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> if session[:image].blank?
> 
> I thought that reloading the div after changing the session variable out  
> would cause a new image to display, but it does nothing.
> 
> –  
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).
> 
> >

–  
Amos K.  
Ramped Media  
USPS  
Programmer/Analyst  
St. Louis, MO  
Looking for something to do? Visit [ImThere.com](http://ImThere.com)

---

<div class="post-metadata">

**Author:** ![d2kagw](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/b5a626/32.png) [@d2kagw](https://www.ruby-forum.com/u/d2kagw)\
**Post date:** [May 18, 2007, 9:01pm UTC](https://www.ruby-forum.com/t/reloading-a-div-with-a-changed-session-variable/104500/3 "2007-05-18T21:01:51Z")

</div>

> What button/link are you hitting that you want to reload the page with?

This creates a list of all the images in the client\_images table  
associated with that client. It appears just below “content\_top”.

 \<% if @images.length \> 1 %\> \<% @images.each\_with\_index do |image, index| %\> \<%= link\_to\_remote index + 1, { :url =\> { :action =\> 'view\_image', :id =\> image } }, { :href =\> url\_for(:action =\> 'view\_image', :id =\> image ) } %\> \<% end %\> \<% end %\>

> What is the name of the function? What is the name of the  
> view? What is the name of the controller? What is the name of the  
> RJS file?

Everything is under the Client controller.

This all takes place under the ‘show’ view and action, ‘view\_image’ is  
the action to cycle out images and is also the name of the RJS.

> Are you passing in info from the app to reload it?

Yes. The value of the image to be changed is passed to the  
session[:image] variable.

The idea is that by default the image shown is the oldest one associated  
with that client. @image is stored in a session variable  
(session[:image]) and called in the image\_tag at the top. If a link in  
the ul is clicked, the ID of the image is passed to the ‘view\_image’  
action.

The view\_image action assigns this new image to the session[:image]  
variable and the RJS reloads the div ‘content\_top’.

---

<div class="post-metadata">

**Author:** ![d2kagw](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/b5a626/32.png) [@d2kagw](https://www.ruby-forum.com/u/d2kagw)\
**Post date:** [July 16, 2008, 3:00am UTC](https://www.ruby-forum.com/t/reloading-a-div-with-a-changed-session-variable/104500/4 "2008-07-16T03:00:20Z")

</div>

hi  
i have a quick question for you if you could help me with it.  
my view is previously set up like this :

\<%= link\_to( image\_tag(session[:slide\_array]  
[session[:slide\_index]], :size =\> “580x146”), session[:slide\_link]  
[session[:slide\_index]] ) %\>

where do slide\_array and slide\_link reside?..It is basically a  
slideshow of images and I have to take off some of the pictures and  
modify them. But I don’t know how to access slide\_array.

I tried to read up on link\_to’s and image\_tag’s APIs, didn’t really  
help.

Any help would be appreciated.

Thank you

On May 18 2007, 12:01 pm, Aaron W. \<rails-mailing-l…@andreas-
