Re: First time on Camping
Hi Magnus, On 17jun, 2010, at 21:04 , Magnus Holm wrote: Hey Raimon, I see that you've been experimenting with Camping and Reststop lately, and just thought I should chime in a bit. You definitely don't *need* Reststop in order to achieve what you want, so it might be a good idea to just leave Reststop until it gets a little more robust. Let's see how we can tackle your problem with Camping only: Thanks for your code. It's true that if I can do what I want with fewer tools/gems, it's a better starter, and once I'm confident I can go further. That's (hopefully) the simplest way to generate XML with Camping. yes! 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? Not sure yet, but maybe Sqlite or PostgreSQL. Normally I use PostgreSQL for all of my RoR projects, but in this case Sqlite would be simpler. The initial data will come from some xml files but I can update the database from another file with Ruby code. In some examples of Camping they just created the database but I couldn't find where they are storing it ... So, the best option is to provide to Camping an existing SQLite database. Here's a Pastie with all the code: http://pastie.org/1008983 (Should work on any version of Camping). thanks, it works and it's very simple :-) Now I'm playing with your code and examples, thanks again! regards, raimon ___ Camping-list mailing list Camping-list@rubyforge.org http://rubyforge.org/mailman/listinfo/camping-list
Re: First time on Camping
Rubygems.org was playing up recently (gems.rubyforge.org forwards to it - see previous posts), and this looks like the same issue... Dave E. Something's not right with your rubygems install maybe try `gem update --system` first? ___ Camping-list mailing list Camping-list@rubyforge.org http://rubyforge.org/mailman/listinfo/camping-list
Re: First time on Camping
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
Re: First time on Camping
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
Re: First time on Camping
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
Re: First time on Camping
Raimon a few things you probably already know but... just in case! 1. because of the preceding '.' in '.camping.db' you'll need to use ls - al to see the file listed (in the ~ home dir) in your file system. 2. In Magnus' example settings (database = list) you can also add a path to your database as well as its name (unless something's changed since I last did it!) e.g.: database = ./data/mydata.db 3. The Firefox SQLite Manager is handy for errr.. managing your SQLite database: https://addons.mozilla.org/en-US/firefox/addon/5817/ Note: with SQLite you cannot change column names once they're in the database (unless anyone knows better?). Dave E. 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). ___ Camping-list mailing list Camping-list@rubyforge.org http://rubyforge.org/mailman/listinfo/camping-list
Re: First time on Camping
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
Re: First time on Camping
Oh, and I also have the speed issue! That's definitely a bug. I'll have a look at it later... On Friday, June 18, 2010, 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 -- // Magnus Holm ___ Camping-list mailing list Camping-list@rubyforge.org http://rubyforge.org/mailman/listinfo/camping-list
Re: First time on Camping
Hi again, I know this is more related to builder than to camping, but not sure where to ask for it ... :-) My app receives .xml file from some different sources, and all of them, except the camping one, are formatted like this: ?xml version=1.0 encoding=UTF-8? person nameJim Fernández/name phone555-1234/phone /person but camping is formatting like this: ?xml version=1.0 encoding=UTF-8? person nameJim Fern#225;ndez/name phone555-1234/phone /person The main difference is the encoding for some chars: á = #225; I can't find in builder how to write values without escaping them ... thanks, r. On 17jun, 2010, at 21:04 , Magnus Holm wrote: And if you want this XML: ?xml version=1.0 encoding=UTF-8? posts post titleHiya/title contentHey/content /post /posts You have this view: module App::Views def posts(xml) xml.posts do @posts.each do |post| xml.post do xml.title(post.title) xml.content(post.content) end end end end end ___ Camping-list mailing list Camping-list@rubyforge.org http://rubyforge.org/mailman/listinfo/camping-list
Re: First time on Camping
Hmm - quickly: in similar setups this usually requires UTF-8 to be specified throughout Camping(?), the database, within your files (and any markup files they generate), and (sometimes) also on the server. Then you can just use/store/retrieve the characters as they are - Dave E The main difference is the encoding for some chars: á = #225; ___ Camping-list mailing list Camping-list@rubyforge.org http://rubyforge.org/mailman/listinfo/camping-list
Re: First time on Camping
This shouldn't be a problem, because that's the way to add non-ASCII characters to XML documents. A proper XML parser should handle it... // Magnus Holm (from my phone) On Friday, June 18, 2010, Raimon Fernandez co...@montx.com wrote: Hi again, I know this is more related to builder than to camping, but not sure where to ask for it ... :-) My app receives .xml file from some different sources, and all of them, except the camping one, are formatted like this: ?xml version=1.0 encoding=UTF-8? person nameJim Fernández/name phone555-1234/phone /person but camping is formatting like this: ?xml version=1.0 encoding=UTF-8? person nameJim Fern#225;ndez/name phone555-1234/phone /person The main difference is the encoding for some chars: á = #225; I can't find in builder how to write values without escaping them ... thanks, r. On 17jun, 2010, at 21:04 , Magnus Holm wrote: And if you want this XML: ?xml version=1.0 encoding=UTF-8? posts post titleHiya/title contentHey/content /post /posts You have this view: module App::Views def posts(xml) xml.posts do �...@posts.each do |post| xml.post do xml.title(post.title) xml.content(post.content) end end end end end ___ Camping-list mailing list Camping-list@rubyforge.org http://rubyforge.org/mailman/listinfo/camping-list -- // Magnus Holm ___ Camping-list mailing list Camping-list@rubyforge.org http://rubyforge.org/mailman/listinfo/camping-list