Welcome Guest | Login

cookies and more

I tried to play with cookies and discoved the next:

1.On my home computer I use Webrick and I created a test controller-
-----------------------------------
class TestController < ApplicationController
def index
currentCookie = cookies['val']#read cookie
      if !currentCookie
$msg = "It looks as if you haven't visited recently"
cookies['val'] = { :value => Time.now.to_s, :expires => Time.now + 360}
     else
$msg = "You last visited #{cookies['val']}---- now:" + Time.now.to_s
     end #if
  end #index
end
----------------------------------------
and index.rhtml : <%=$msg%>
2. It works perfectly on my home computer. If I don't have any cookies, they are created and died after 1 hour.
But it doesn't work on hostingrails.com. Any idea?


And more.. On my home computer I have a file count.txt in my public folder. How to make
Webrick undestand f= File.open("count.txt", "r+") instead of f= File.open("./public/count.txt", "r+").
Thanks.

2006-10-05 05:09 PM

OK, first of all you only are allowing the cookie to remain for 6 minutes instead of 1 hr.  That may have been a typo but make sure it is set to 3600.  Otherwise it looks ok.  

Also, have you symlinked the public folder of your app to the public_html of your account?  See here to learn how to do this if you haven't already.  

Let me know how it goes.  

2006-10-05 08:48 PM

1. Cookies.
On my home computer it works the next way - at first running you see- "It looks as if you haven't visited recently"
and after reloading the page --"You last visited #{cookies['val']}---- now:" + Time.now.to_s - you see two different times.

On hostingrails.com I always see -"It looks as if you haven't visited recently" even after the page was reloaded.
 
2. Path to file. The question was - how to reconfig my home Rails with Webrick. Now it understands
File.open("./public/count.txt", "r+"), but I want - File.open("count.txt", "r+").

Thanks

2006-10-06 09:21 AM

How are you accessing your site on HostingRails? If you're not on port 80 through your domain then sessions/cookies can get jacked..  This also can explain question 2.

2006-10-06 09:26 AM

You can try www.onishvalen/test by yourself?

2006-10-13 03:32 PM

Looks like its working for me.  I came to the page and reloaded and I see this -

You last visited Fri Oct 13 15:44:13 MDT 2006---- now:Fri Oct 13 15:44:24 MDT 2006

2006-10-13 03:48 PM

But when I try www.onishvalen.com/test - I see-- looks as if you haven't visited recently -- and nothing changes after reloading. Why?

2006-10-13 04:18 PM

I assume you have cookies enabled on your browser.  Try another browser and see if it works (I used FireFox)

2006-10-13 04:26 PM

I have cookies enabled on my browser (IE and Maxthon) and when I try the same task on http://localhost:3000/test (Webrick uses 3000 port) it works.

2006-10-13 04:42 PM

I have seen problems with cookie permissions if you ever ran webrick on a hostingrails server - that's not good - you'll have to first try to delete the files in your tmp folder and try again , and if that doesn't work you'll need to give your app a fresh start.  

However, i haven't been able to reproduce the problem.  Have you tried clearing your cookies? Give it a try with firefox.  

2006-10-13 04:51 PM


Hello Guest! In order to post you must be an active client with us, please log in or sign up today!