Ruby on Rails: Talk
2008-Sep-01 12:40 UTC
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 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Frederick Cheung
2008-Sep-01 12:46 UTC
Re: Trying to using if loop with session stored value but it won''t fork
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 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Ruby on Rails: Talk
2008-Sep-01 12:49 UTC
Re: Trying to using if loop with session stored value but it won''t fork
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 Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> 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--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
SriSri
2008-Sep-01 15:07 UTC
Re: Trying to using if loop with session stored value but it won''t fork
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...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> 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 Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > wrote: > > > 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--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---