On Tue, Jun 09, 2009 at 11:35:26AM +0100, Dave Everitt wrote:
Any feedback appreciated on the following. My most recent attempt to identify the issue is a minimal Ruby/SQLite/ActiveRecord script, Pastied here: http://pastie.textmate.org/492514 which brings up the following when run from the command line (an empty database file already exists):

$ ./simple_db.rbx
[SNIP]/active_record/connection_adapters/sqlite3_adapter.rb:29:in `table_structure': Could not find table 'users'

(1) Not really a 'camping' related pastie. See (3) for the same thing
done the 'camping way'.

(2) There seems to be nothing in the code above telling activerecord
to create your database schema unless you're doing seperate rake
db:migrate scripts outside of this script.  My suspicion, therefore is
that the 'users' table simply does not exist in your database.

(3) This is a full working solution for camping 1.5:
#!/usr/bin/env ruby

$:.unshift File.dirname(__FILE__) + "/../../lib"
require 'camping'

Camping.goes :Dave

module Dave::Models
  class User < Base
  end
  class CreateTables < V 1.0
    def self.up
      create_table :dave_users, :force => true do |t|
        t.column :id,       :integer, :null => false
        t.column :name,     :string,  :limit => 255
        t.column :password, :string,  :limit => 255
      end
      def self.down
        drop_table :dave_users
      end

    end
  end
end

module Dave::Controllers
  class Index < R '/'
    def get
      user = User.new()
      user.id = "dave"
      user.name = "Dave Everitt"
      user.password = "davepass"
      user.save

      # user = User.find("dave")
      # user.destroy()

      render :fin
    end
  end
end

module Dave::Views
  def fin
    "Finished, no errors"
  end
end

def Dave.create
  Dave::Models.create_schema :assume => (Dave::Models::User.table_exists? ? 1.0 
: 0.0)
end


***************************
Save this file as dave.rb. Note the Dave::Models.create_schema call
(as per point 2 above)

To get this to work I have the following gems installed:
$ gem list

*** LOCAL GEMS ***

activerecord (2.3.2)
activesupport (2.3.2)
builder (2.1.2)
camping (1.5.180)
markaby (0.5)
metaid (1.0)
sqlite3-ruby (1.2.4)

I run it with:
camping dave.rb

I then visited http://localhost:3301/ with my browser (which showed
"Finished, no errors").

To confirm that there is a table in the sqlite database with the
correct fields and with one record:

$ sqlite3 ~/.camping.db
SQLite version 3.6.10
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
sqlite> .tables
dave_schema_infos dave_users sessions sqlite> .header on
sqlite> select * from dave_users;
id|name|password
0|Dave Everitt|davepass

Hope some of the above points you in the 'right' direction.

Cheers,
Jonathan.
_______________________________________________
Camping-list mailing list
Camping-list@rubyforge.org
http://rubyforge.org/mailman/listinfo/camping-list

Reply via email to