Excellent!

Camping uses Rack, so it should be very simple to get it running on
any Ruby web server. Just create a config.ru like this:

  require 'list'
  List.create if List.respond_to?(:create) # call List.create if it exists
  run List # and run the app!

Then you can start it with: `thin start` (when you're in the app directory)

One thing you'll have to remember is that any exceptions which are
raised, won't be rescued inside Camping, but rather be raised all the
way up. Thin (hopefully) catches it somewhere, but you should probably
handle it yourself:

module List
  def r500(klass, method, exception)
    # Do some funky things
    "There was an exception in #{klass}.#{method}: #{exception}"
  end
end

You could also use something like http://hoptoadapp.com/ (they have
free plans) which gives you a nice dashboard and sends you an email
every time an exception is raised. Just create an account, run `gem
install toadhopper` and add this to your app:

require 'toadhopper'

module List
  ExceptionHandler = Toadhopper.new("YOUR API KEY")
  def r500(klass, method, exception)
    # Send the exception to Hoptoad:
    ExceptionHandler.post!(exception)
    # Render something for the user. You would probably want to render some XML
    # so the client knows something went wrong.
    "There was an exception in #{klass}.#{method}: #{exception}"
  end
end

// Magnus Holm



On Fri, Jun 18, 2010 at 13:23, Raimon Fernandez <co...@montx.com> wrote:
> buf, now I'm lost ...
>
> :-))
>
> no, really, thanks for that info, now I have working as I want ...
>
> :-)
>
>
> I've tested and created a new databse, and is working also.
>
> I've created a new sqlite3 from terminal and filled-up with some data and now 
> I can use this databse from Camping, cool!
>
> And, caping is serving the data with .xml format and I can get it from my 
> devices, cool!
>
> I'm going to play more with thise, sure I'll come back with more questions ...
>
> :-)
>
> ah, I always use Thin with Nginx for my RoR instead of Mongrel, I suppose 
> there would be no problem with camping ?
>
> and speed: normally it's all very fast, but sometimes, it takes a little bit 
> (3 or more seconds) to respond camping, and I'm not doing nothing serious at 
> all, just the example from pastie.
>
> is because I'm using the development mode instead of production, like in RoR ?
>
> thanks again !
>
> regards,
>
> r.
>
>
>
> On 18jun, 2010, at 12:33 , Magnus Holm wrote:
>
>> 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
>
>
> _______________________________________________
> 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