Yeah, people always get a little confused because you don't need to
define your database when you're using bin/camping (it has a default
SQLite database at ~/.camping.db).

I also see that there's some old, database code here; we definitely
need to update our documentation (yes, I'm working on it!)

First of all, the table name should be "list_people" (since "people"
is the plural to "person" and the table names are always in
lowercase), but you should rather do `create_table Person.table_name`
and `drop_table Person.table_name` because then you don't need to
think about it at all :-)

Secondly, you only need this in order to create the database:

def List.create
  List::Models.create_schema
end

Then it will use a SQLite database at ~/.camping.db (as long as you
start it with `camping list.rb`). This is perfect for just testing
things out (you can also run `camping -C list.rb` to get an IRB
console). Please note that if you only run `camping list.rb`, you'll
have to load the page in the browser before the migrations run.

If you want to use a specific database, you can add this:

def List.create
  List::Models::Base.establish_connection(
    :adapter => "postgresql",
    :username => "root",
    :password => "toor,
    :database => "list"
  )
  List::Models.create_schema
end

Or you might want to add the information in a database.yml file:

---
adapter: postgresql
username: root
password: toor
database: list

And then rather do:

require 'yaml'

def List.create
  List::Models::Base.establish_connection(YAML.load(File.read("database.yml")))
  List::Models.create_schema
end

Please note that if you connect to a database which already has the
tables, DON'T run `List::Models.create_schema` as this will probably
delete the whole database. General rule: you only need migrations to
setup the database.

--

And thirdly: Yes, we are aware of that the migration support isn't
very nice. In the future we hope to have something like:

module List::Models
  class Person
    t.string :name
  end
end

def List.create
  List::Models.setup!
end

Until then, you'll have to stick with the current solution :-)


// Magnus Holm



On Fri, Jun 18, 2010 at 11:09, Raimon Fernandez <co...@montx.com> wrote:
>
> On 17jun, 2010, at 21:04 , Magnus Holm wrote:
>
>>
>> That's (hopefully) the simplest way to generate XML with Camping.
>>
>> You still need to create a model to store/retrieve the data. Before we
>> can help you here, we need to know a few things: Is it going to fetch
>> data from a specific place, or should it create its own database (from
>> scratch)? Any specific database you want to use?
>>
>> Here's a Pastie with all the code: http://pastie.org/1008983 (Should
>> work on any version of Camping).
>
> I'm trying to adapt your pastie to use a sqlite databse, but I'm having some 
> errors that I can't see ...
>
> Here's a Pastie with all code: http://pastie.org/1009797
>
> I'm just trying to create with code a simple table called Persons with some 
> fields but ...
>
> :-)
>
> Also,  I can't find where is creating the database ...
>
> thanks,
>
> regards,
>
> r.
> _______________________________________________
> Camping-list mailing list
> Camping-list@rubyforge.org
> http://rubyforge.org/mailman/listinfo/camping-list
>
_______________________________________________
Camping-list mailing list
Camping-list@rubyforge.org
http://rubyforge.org/mailman/listinfo/camping-list

Reply via email to