# Camping not saving @state

**URL:** <https://www.ruby-forum.com/t/camping-not-saving-state/144274>\
**Category:** Ruby\
**Created:** [July 28, 2008, 2:56am UTC](https://www.ruby-forum.com/t/camping-not-saving-state/144274 "2008-07-28T02:56:32Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![no137b](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/bb73d2/32.png) [@no137b](https://www.ruby-forum.com/u/no137b)\
**Post date:** [July 28, 2008, 2:56am UTC](https://www.ruby-forum.com/t/camping-not-saving-state/144274/1 "2008-07-28T02:56:32Z")

</div>

I have a sqlite3 database with the sessions table and schema set up  
correctly. Sessions are created fine and put in the table, the cookie  
is set with the correct hash and the hash is found again but when  
using @state the values arenâ€™t updated in the table.

I know that Session::service is called and the contents of the record  
are put into session like so:  
#\<Camping::Models::Session id: 1, hashid:  
“iSCMSIzV7ITsRTr0UMA8Gko3LEnY3bw4”, created\_at: “2008-07-24 17:11:43”,  
ivars: {}\>

I do @state.user = 5, then it then gets as far as making session look  
like this:  
#\<Camping::Models::Session id: 1, hashid:  
“iSCMSIzV7ITsRTr0UMA8Gko3LEnY3bw4”, created\_at: “2008-07-24 17:11:43”,  
ivars: {“TLCMS”=\>{“user”=\>5}}\>

But then session.save doesnâ€™t write to the table, and doesnâ€™t throw an  
error (session.save! doesnâ€™t either). Can anyone see what is going  
wrong?

---

<div class="post-metadata">

**Author:** ![no137b](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/bb73d2/32.png) [@no137b](https://www.ruby-forum.com/u/no137b)\
**Post date:** [July 28, 2008, 11:44pm UTC](https://www.ruby-forum.com/t/camping-not-saving-state/144274/2 "2008-07-28T23:44:28Z")

</div>

As far as I remember the saving is automatic, why\_ always makes it  
easier not harder  
you shouldn’t need to call save. Have you checked the database from  
sqlite’s utility?

---

<div class="post-metadata">

**Author:** ![no137b](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/bb73d2/32.png) [@no137b](https://www.ruby-forum.com/u/no137b)\
**Post date:** [July 28, 2008, 11:57pm UTC](https://www.ruby-forum.com/t/camping-not-saving-state/144274/3 "2008-07-28T23:57:21Z")

</div>

On Tue Jul 29 06:43:14 2008, jonty wrote:

> > is set with the correct hash and the hash is found again but when  
> > #\<Camping::Models::Session id: 1, hashid:  
> > “iSCMSIzV7ITsRTr0UMA8Gko3LEnY3bw4”, created\_at: “2008-07-24 17:11:43”,  
> > ivars: {“TLCMS”=\>{“user”=\>5}}\>
> > 
> > But then session.save doesnâ€™t write to the table, and doesnâ€™t throw an  
> > error (session.save! doesnâ€™t either). Can anyone see what is going  
> > wrong?

Iâ€™m not calling save, I just added prints in the camping source for  
debugging and I found that it does in fact call save, but isnâ€™t saved.

Looking through sqlite3(1) the sessions are created, but their  
contents is not saved.

---

<div class="post-metadata">

**Author:** ![no137b](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/bb73d2/32.png) [@no137b](https://www.ruby-forum.com/u/no137b)\
**Post date:** [July 29, 2008, 5:41pm UTC](https://www.ruby-forum.com/t/camping-not-saving-state/144274/4 "2008-07-29T17:41:19Z")

</div>

Thanks for finding the problem as I am using Camping quite a bit at the  
minute - do you know how to use your own database instead of camping.db?  
I tried putting another db name in the postamble as I have seen in  
examples but it still just uses camping.db.

---

<div class="post-metadata">

**Author:** ![no137b](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/bb73d2/32.png) [@no137b](https://www.ruby-forum.com/u/no137b)\
**Post date:** [July 29, 2008, 6:16pm UTC](https://www.ruby-forum.com/t/camping-not-saving-state/144274/5 "2008-07-29T18:16:28Z")

</div>

On Wed Jul 30 00:40:11 2008, jonty wrote:

> 

I am using FastCGI, my dispatch.rb looks like this:

require ‘rubygems’  
gem ‘activerecord’, ‘=2.0.2’  
require ‘camping/fastcgi’

Camping::Models::Base.establish\_connection :adapter =\> ‘sqlite3’,  
:database =\> ‘/tmp/tlcms.rb’

Camping::FastCGI.serve("/usr/pkg/share/httpd/htdocs/tlcms2/tlcms.rb")

So I donâ€™t need a PostAmble.

---

<div class="post-metadata">

**Author:** ![no137b](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/bb73d2/32.png) [@no137b](https://www.ruby-forum.com/u/no137b)\
**Post date:** [July 29, 2008, 4:07pm UTC](https://www.ruby-forum.com/t/camping-not-saving-state/144274/6 "2008-07-29T16:07:29Z")

</div>

Okay the problem was with ActiveRecord 2.1, downgrading to 2.0.2 fixed  
it.

---

<div class="post-metadata">

**Author:** ![no137b](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/bb73d2/32.png) [@no137b](https://www.ruby-forum.com/u/no137b)\
**Post date:** [July 29, 2008, 6:20pm UTC](https://www.ruby-forum.com/t/camping-not-saving-state/144274/7 "2008-07-29T18:20:34Z")

</div>

On Wed Jul 30 01:15:29 2008, Fred P. wrote:

> Camping::Models::Base.establish\_connection :adapter =\> ‘sqlite3’,  
> :database =\> ‘/tmp/tlcms.rb’

Sorry, that should be /tmp/tlcms.db
