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

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

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

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.

= 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

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.

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" <dazzaroo...@gmail.com> wrote: