# Trying to using if loop with session stored value but it won't fork

**URL:** <https://www.ruby-forum.com/t/trying-to-using-if-loop-with-session-stored-value-but-it-wont-fork/147403>\
**Category:** Rails\
**Created:** [September 1, 2008, 2:41pm UTC](https://www.ruby-forum.com/t/trying-to-using-if-loop-with-session-stored-value-but-it-wont-fork/147403 "2008-09-01T14:41:53Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ruby\_on\_RailsS\_Talk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/dbc845/32.png) [@Ruby\_on\_RailsS\_Talk](https://www.ruby-forum.com/u/Ruby_on_RailsS_Talk)\
**Post date:** [September 1, 2008, 2:41pm UTC](https://www.ruby-forum.com/t/trying-to-using-if-loop-with-session-stored-value-but-it-wont-fork/147403/1 "2008-09-01T14:41:53Z")

</div>

Hi

I’ve been trying to get the following code to work. I’m sure it must  
be something simple. As you can see, the session is forced to hold the  
value of ‘week’.

I simply need to check if the value session[:calview] is day. If it  
isn’t then it’ll store 7 days into an array.

I’ve put the code into my controller and it simply won’t go to the  
‘else’ statement. I’ve left in the logger.warn statements for you to  
see. I’ve even tried to use a different variable just in case I was  
doing something to session.

session[:calview] = “week”  
currentcalview = session[:calview]  
logger.warn(“Session holds (new): #{currentcalview}”)  
if currentcalview = ‘day’  
#Just list the calendar for one day  
@dates = session[:dateviewing]  
logger.warn (“I am inside the day viewer with date #{@dates}”)  
else  
#Means we wish to look at the week  
@dates = []  
startdate = session[:dateviewing]  
curdate = startdate  
enddate = startdate + 7.days  
logger.warn(“I am inside the week viewer: Curdate #{curdate} End  
Date: #{enddate}”)  
while curdate \< enddate do  
@dates.push(curdate)  
curdate += 1.day  
end  
logger.warn(“I am here with the following date(s) for the week  
#{@dates}”)  
end

I’m sure there are nicer ways of putting 7 dates into an array given a  
start date but I’m trying to cobble together bits of code from a  
(short!) lifetime of pascal, c, vb, php, perl and lots of others! My  
brains’ not coping too well as you can see! Any help to make the code  
“nicer” would also be appreciated.

Any help in trying to work out what I’m doing wrong greatly  
appreciated.

Cheers

Darren

---

<div class="post-metadata">

**Author:** ![Ruby\_on\_RailsS\_Talk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/dbc845/32.png) [@Ruby\_on\_RailsS\_Talk](https://www.ruby-forum.com/u/Ruby_on_RailsS_Talk)\
**Post date:** [September 1, 2008, 2:47pm UTC](https://www.ruby-forum.com/t/trying-to-using-if-loop-with-session-stored-value-but-it-wont-fork/147403/2 "2008-09-01T14:47:09Z")

</div>

On 1 Sep 2008, at 13:40, Ruby on Rails: Talk wrote:

> I’ve put the code into my controller and it simply won’t go to the  
> ‘else’ statement. I’ve left in the logger.warn statements for you to  
> see. I’ve even tried to use a different variable just in case I was  
> doing something to session.

= is not comparison in ruby (== is). = is assignment, which evaluates  
to the thing you are assigning, ie in your case ‘day’ which isn’t false

Fred

---

<div class="post-metadata">

**Author:** ![Ruby\_on\_RailsS\_Talk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/dbc845/32.png) [@Ruby\_on\_RailsS\_Talk](https://www.ruby-forum.com/u/Ruby_on_RailsS_Talk)\
**Post date:** [September 1, 2008, 2:50pm UTC](https://www.ruby-forum.com/t/trying-to-using-if-loop-with-session-stored-value-but-it-wont-fork/147403/3 "2008-09-01T14:50:41Z")

</div>

Yes!

Thanks. It’s now checking properly.

Stupid mistake but I’ve been looking at this for over an hour and I  
was about to throw either computer or myself out of the window.

On Sep 1, 1:46 pm, Frederick C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![Ruby\_on\_RailsS\_Talk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/dbc845/32.png) [@Ruby\_on\_RailsS\_Talk](https://www.ruby-forum.com/u/Ruby_on_RailsS_Talk)\
**Post date:** [September 1, 2008, 5:08pm UTC](https://www.ruby-forum.com/t/trying-to-using-if-loop-with-session-stored-value-but-it-wont-fork/147403/4 "2008-09-01T17:08:32Z")

</div>

I use Net Beans IDE for ruby and it catches right away. You might want  
to try it, especially if you are new to ruby/rails.

Sri

On Sep 1, 8:49 am, “Ruby on Rails: Talk” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
