activerecord-postgres-hstore 0.1.0 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (66) hide show
  1. data/.rspec +1 -0
  2. data/Gemfile +14 -0
  3. data/Gemfile.lock +38 -0
  4. data/README.textile +23 -6
  5. data/Rakefile +37 -28
  6. data/VERSION +1 -1
  7. data/activerecord-postgres-hstore.gemspec +127 -0
  8. data/app/.gitignore +4 -0
  9. data/app/Gemfile +27 -0
  10. data/app/Gemfile.lock +75 -0
  11. data/app/README +256 -0
  12. data/app/Rakefile +7 -0
  13. data/app/app/controllers/application_controller.rb +3 -0
  14. data/app/app/helpers/application_helper.rb +2 -0
  15. data/app/app/models/bar.rb +3 -0
  16. data/app/app/models/foo.rb +3 -0
  17. data/app/app/views/layouts/application.html.erb +14 -0
  18. data/app/bench.rb +76 -0
  19. data/app/bench_results.txt +13 -0
  20. data/app/config.ru +4 -0
  21. data/app/config/application.rb +42 -0
  22. data/app/config/boot.rb +13 -0
  23. data/app/config/database.yml +51 -0
  24. data/app/config/environment.rb +5 -0
  25. data/app/config/environments/development.rb +22 -0
  26. data/app/config/environments/production.rb +49 -0
  27. data/app/config/environments/test.rb +35 -0
  28. data/app/config/initializers/activerecord_postgres_hstore.rb +0 -0
  29. data/app/config/initializers/backtrace_silencers.rb +7 -0
  30. data/app/config/initializers/inflections.rb +10 -0
  31. data/app/config/initializers/mime_types.rb +5 -0
  32. data/app/config/initializers/secret_token.rb +7 -0
  33. data/app/config/initializers/session_store.rb +8 -0
  34. data/app/config/locales/en.yml +5 -0
  35. data/app/config/routes.rb +58 -0
  36. data/app/db/development_structure.sql +578 -0
  37. data/app/db/migrate/20100906191151_add_hstore.rb +276 -0
  38. data/app/db/migrate/20100906191457_create_foos.rb +13 -0
  39. data/app/db/migrate/20100906191506_create_bars.rb +12 -0
  40. data/app/db/schema.rb +15 -0
  41. data/app/db/seeds.rb +7 -0
  42. data/app/doc/README_FOR_APP +2 -0
  43. data/app/generate_copy_files.rb +47 -0
  44. data/app/lib/tasks/.gitkeep +0 -0
  45. data/app/public/404.html +26 -0
  46. data/app/public/422.html +26 -0
  47. data/app/public/500.html +26 -0
  48. data/app/public/favicon.ico +0 -0
  49. data/app/public/images/rails.png +0 -0
  50. data/app/public/index.html +262 -0
  51. data/app/public/javascripts/.gitkeep +0 -0
  52. data/app/public/javascripts/application.js +0 -0
  53. data/app/public/robots.txt +5 -0
  54. data/app/public/stylesheets/.gitkeep +0 -0
  55. data/app/script/rails +6 -0
  56. data/app/test/performance/browsing_test.rb +9 -0
  57. data/app/test/test_helper.rb +6 -0
  58. data/app/test/unit/bar_test.rb +133 -0
  59. data/app/test/unit/foo_test.rb +8 -0
  60. data/app/vendor/plugins/.gitkeep +0 -0
  61. data/lib/activerecord-postgres-hstore/hash.rb +1 -1
  62. data/lib/activerecord-postgres-hstore/string.rb +4 -0
  63. data/spec/activerecord-postgres-hstore_spec.rb +13 -9
  64. data/spec/spec_helper.rb +4 -4
  65. metadata +162 -20
  66. data/.gitignore +0 -21
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color --format doc
data/Gemfile ADDED
@@ -0,0 +1,14 @@
1
+ source "http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ gem 'activerecord'
4
+ gem 'rake'
5
+
6
+ # Add dependencies to develop your gem here.
7
+ # Include everything needed to run rake, tests, features, etc.
8
+ group :development do
9
+ gem "shoulda", ">= 0"
10
+ gem "bundler", "~> 1.0.0"
11
+ gem "jeweler", "~> 1.6.4"
12
+ gem "rcov", ">= 0"
13
+ gem "rdoc"
14
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,38 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ activemodel (3.0.9)
5
+ activesupport (= 3.0.9)
6
+ builder (~> 2.1.2)
7
+ i18n (~> 0.5.0)
8
+ activerecord (3.0.9)
9
+ activemodel (= 3.0.9)
10
+ activesupport (= 3.0.9)
11
+ arel (~> 2.0.10)
12
+ tzinfo (~> 0.3.23)
13
+ activesupport (3.0.9)
14
+ arel (2.0.10)
15
+ builder (2.1.2)
16
+ git (1.2.5)
17
+ i18n (0.5.0)
18
+ jeweler (1.6.4)
19
+ bundler (~> 1.0)
20
+ git (>= 1.2.5)
21
+ rake
22
+ rake (0.9.2)
23
+ rcov (0.9.9)
24
+ rdoc (3.9.1)
25
+ shoulda (2.11.3)
26
+ tzinfo (0.3.29)
27
+
28
+ PLATFORMS
29
+ ruby
30
+
31
+ DEPENDENCIES
32
+ activerecord
33
+ bundler (~> 1.0.0)
34
+ jeweler (~> 1.6.4)
35
+ rake
36
+ rcov
37
+ rdoc
38
+ shoulda
data/README.textile CHANGED
@@ -22,19 +22,21 @@ Benchmarks made in my local machine, with a million records. Time is in millisec
22
22
 
23
23
  h2. Requirements
24
24
 
25
- Postgresql 8.4 with contrib and Rails 3. (It might work on 2.3.x with minor patches...)
25
+ Postgresql 8.4+ (also tested with 9.0) with contrib and Rails 3. (It might work on 2.3.x with minor patches...)
26
26
 
27
- In Ubuntu, this is easy:
27
+ On Ubuntu, this is easy:
28
28
 
29
- @sudo apt-get install postgresql-8.4 postgresql-contrib-8.4@
29
+ @sudo apt-get install postgresql-contrib-9.0@
30
30
 
31
- In Mac ...you are screwed. Use a VM.
31
+ On Mac <del>...you are screwed. Use a VM.</del> you should use "the binary package kindly provided by EnterpriseDB":http://www.enterprisedb.com/products-services-training/pgdownload#osx
32
+
33
+ "Homebrew's":https://github.com/mxcl/homebrew Postgres installation also includes the contrib packages. @brew install postgres@
32
34
 
33
35
  h2. Install
34
36
 
35
37
  Hstore is a postgres contrib type. Check it out first:
36
38
 
37
- "http://www.postgresql.org/docs/8.4/static/hstore.html":http://www.postgresql.org/docs/8.4/static/hstore.html
39
+ "http://www.postgresql.org/docs/9.0/static/hstore.html":http://www.postgresql.org/docs/9.0/static/hstore.html
38
40
 
39
41
  Then, just add this to your Gemfile:
40
42
 
@@ -44,6 +46,21 @@ And run your bundler:
44
46
 
45
47
  @bundle install@
46
48
 
49
+ Make sure that you have the desired database, if not create it as the desired user:
50
+
51
+ @createdb hstorage_dev@
52
+
53
+ Add the parameters to your database.yml (these are system dependant), e.g.:
54
+
55
+ bc. development:
56
+ adapter: postgresql
57
+ host: 127.0.0.1
58
+ database: hstorage_dev
59
+ encoding: unicode
60
+ username: postgres
61
+ password:
62
+ pool: 5
63
+
47
64
  Now you need to create a migration that adds hstore support for your postgresql database:
48
65
 
49
66
  @rails g hstore:setup@
@@ -69,7 +86,7 @@ To my experience GIN is faster for searching records.
69
86
 
70
87
  h2. Usage
71
88
 
72
- Once you have it installed, you just need to learn a little bit of new sqls for selecting stuff (creting and updating is transparent).
89
+ Once you have it installed, you just need to learn a little bit of new sqls for selecting stuff (creating and updating is transparent).
73
90
 
74
91
  Find records that contains a key named 'foo':
75
92
 
data/Rakefile CHANGED
@@ -1,42 +1,51 @@
1
+ # encoding: utf-8
2
+
1
3
  require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
2
12
  require 'rake'
3
13
 
4
- begin
5
- require 'jeweler'
6
- Jeweler::Tasks.new do |gem|
7
- gem.name = "activerecord-postgres-hstore"
8
- gem.summary = %Q{Goodbye serialize, hello hstore}
9
- gem.description = %Q{This gem adds support for the postgres hstore type. It is the _just right_ alternative for storing hashes instead of using seralization or dynamic tables.}
10
- gem.email = "juanmaiz@gmail.com"
11
- gem.homepage = "http://github.com/softa/activerecord-postgres-hstore"
12
- gem.authors = ["Juan Maiz"]
13
- gem.add_development_dependency "rspec", ">= 1.2.9"
14
- gem.files = FileList['.document', '.gitignore', 'LICENSE', 'README.rdoc', 'Rakefile', 'VERSION', 'spec/**/*_spec.rb', 'lib/**/*.rb'].to_a
15
- # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
16
- end
17
- Jeweler::GemcutterTasks.new
18
- rescue LoadError
19
- puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
+ gem.name = "activerecord-postgres-hstore"
18
+ gem.summary = %Q{Goodbye serialize, hello hstore}
19
+ gem.description = %Q{This gem adds support for the postgres hstore type. It is the _just right_ alternative for storing hashes instead of using seralization or dynamic tables.}
20
+ gem.email = "juanmaiz@gmail.com"
21
+ gem.homepage = "http://github.com/softa/activerecord-postgres-hstore"
22
+ gem.authors = ["Juan Maiz", "Diogo Biazus"]
23
+ gem.license = "MIT"
24
+ # dependencies defined in Gemfile
20
25
  end
26
+ Jeweler::RubygemsDotOrgTasks.new
21
27
 
22
- require 'spec/rake/spectask'
23
- Spec::Rake::SpecTask.new(:spec) do |spec|
24
- spec.libs << 'lib' << 'spec'
25
- spec.spec_files = FileList['spec/**/*_spec.rb']
28
+ require 'rake/testtask'
29
+ Rake::TestTask.new(:test) do |test|
30
+ test.libs << 'lib' << 'test'
31
+ test.pattern = 'test/**/test_*.rb'
32
+ test.verbose = true
26
33
  end
27
34
 
28
- Spec::Rake::SpecTask.new(:rcov) do |spec|
29
- spec.libs << 'lib' << 'spec'
30
- spec.pattern = 'spec/**/*_spec.rb'
31
- spec.rcov = true
35
+ require 'rcov/rcovtask'
36
+ Rcov::RcovTask.new do |test|
37
+ test.libs << 'test'
38
+ test.pattern = 'test/**/test_*.rb'
39
+ test.verbose = true
40
+ test.rcov_opts << '--exclude "gems/*"'
32
41
  end
33
42
 
34
- task :spec => :check_dependencies
35
- task :default => :spec
43
+ task :default => :test
36
44
 
37
- require 'rake/rdoctask'
38
- Rake::RDocTask.new do |rdoc|
45
+ require 'rdoc/task'
46
+ RDoc::Task.new do |rdoc|
39
47
  version = File.exist?('VERSION') ? File.read('VERSION') : ""
48
+
40
49
  rdoc.rdoc_dir = 'rdoc'
41
50
  rdoc.title = "activerecord-postgres-hstore #{version}"
42
51
  rdoc.rdoc_files.include('README*')
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.1.2
@@ -0,0 +1,127 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{activerecord-postgres-hstore}
8
+ s.version = "0.1.2"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Juan Maiz", "Diogo Biazus"]
12
+ s.date = %q{2011-08-02}
13
+ s.description = %q{This gem adds support for the postgres hstore type. It is the _just right_ alternative for storing hashes instead of using seralization or dynamic tables.}
14
+ s.email = %q{juanmaiz@gmail.com}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE",
17
+ "README.textile"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".rspec",
22
+ "Gemfile",
23
+ "Gemfile.lock",
24
+ "LICENSE",
25
+ "README.textile",
26
+ "Rakefile",
27
+ "VERSION",
28
+ "activerecord-postgres-hstore.gemspec",
29
+ "app/.gitignore",
30
+ "app/Gemfile",
31
+ "app/Gemfile.lock",
32
+ "app/README",
33
+ "app/Rakefile",
34
+ "app/app/controllers/application_controller.rb",
35
+ "app/app/helpers/application_helper.rb",
36
+ "app/app/models/bar.rb",
37
+ "app/app/models/foo.rb",
38
+ "app/app/views/layouts/application.html.erb",
39
+ "app/bench.rb",
40
+ "app/bench_results.txt",
41
+ "app/config.ru",
42
+ "app/config/application.rb",
43
+ "app/config/boot.rb",
44
+ "app/config/database.yml",
45
+ "app/config/environment.rb",
46
+ "app/config/environments/development.rb",
47
+ "app/config/environments/production.rb",
48
+ "app/config/environments/test.rb",
49
+ "app/config/initializers/activerecord_postgres_hstore.rb",
50
+ "app/config/initializers/backtrace_silencers.rb",
51
+ "app/config/initializers/inflections.rb",
52
+ "app/config/initializers/mime_types.rb",
53
+ "app/config/initializers/secret_token.rb",
54
+ "app/config/initializers/session_store.rb",
55
+ "app/config/locales/en.yml",
56
+ "app/config/routes.rb",
57
+ "app/db/development_structure.sql",
58
+ "app/db/migrate/20100906191151_add_hstore.rb",
59
+ "app/db/migrate/20100906191457_create_foos.rb",
60
+ "app/db/migrate/20100906191506_create_bars.rb",
61
+ "app/db/schema.rb",
62
+ "app/db/seeds.rb",
63
+ "app/doc/README_FOR_APP",
64
+ "app/generate_copy_files.rb",
65
+ "app/lib/tasks/.gitkeep",
66
+ "app/public/404.html",
67
+ "app/public/422.html",
68
+ "app/public/500.html",
69
+ "app/public/favicon.ico",
70
+ "app/public/images/rails.png",
71
+ "app/public/index.html",
72
+ "app/public/javascripts/.gitkeep",
73
+ "app/public/javascripts/application.js",
74
+ "app/public/robots.txt",
75
+ "app/public/stylesheets/.gitkeep",
76
+ "app/script/rails",
77
+ "app/test/performance/browsing_test.rb",
78
+ "app/test/test_helper.rb",
79
+ "app/test/unit/bar_test.rb",
80
+ "app/test/unit/foo_test.rb",
81
+ "app/vendor/plugins/.gitkeep",
82
+ "lib/activerecord-postgres-hstore.rb",
83
+ "lib/activerecord-postgres-hstore/activerecord.rb",
84
+ "lib/activerecord-postgres-hstore/hash.rb",
85
+ "lib/activerecord-postgres-hstore/string.rb",
86
+ "lib/templates/setup_hstore.rb",
87
+ "spec/activerecord-postgres-hstore_spec.rb",
88
+ "spec/spec_helper.rb"
89
+ ]
90
+ s.homepage = %q{http://github.com/softa/activerecord-postgres-hstore}
91
+ s.licenses = ["MIT"]
92
+ s.require_paths = ["lib"]
93
+ s.rubygems_version = %q{1.3.7}
94
+ s.summary = %q{Goodbye serialize, hello hstore}
95
+
96
+ if s.respond_to? :specification_version then
97
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
98
+ s.specification_version = 3
99
+
100
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
101
+ s.add_runtime_dependency(%q<activerecord>, [">= 0"])
102
+ s.add_runtime_dependency(%q<rake>, [">= 0"])
103
+ s.add_development_dependency(%q<shoulda>, [">= 0"])
104
+ s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
105
+ s.add_development_dependency(%q<jeweler>, ["~> 1.6.4"])
106
+ s.add_development_dependency(%q<rcov>, [">= 0"])
107
+ s.add_development_dependency(%q<rdoc>, [">= 0"])
108
+ else
109
+ s.add_dependency(%q<activerecord>, [">= 0"])
110
+ s.add_dependency(%q<rake>, [">= 0"])
111
+ s.add_dependency(%q<shoulda>, [">= 0"])
112
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
113
+ s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
114
+ s.add_dependency(%q<rcov>, [">= 0"])
115
+ s.add_dependency(%q<rdoc>, [">= 0"])
116
+ end
117
+ else
118
+ s.add_dependency(%q<activerecord>, [">= 0"])
119
+ s.add_dependency(%q<rake>, [">= 0"])
120
+ s.add_dependency(%q<shoulda>, [">= 0"])
121
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
122
+ s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
123
+ s.add_dependency(%q<rcov>, [">= 0"])
124
+ s.add_dependency(%q<rdoc>, [">= 0"])
125
+ end
126
+ end
127
+
data/app/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ .bundle
2
+ db/*.sqlite3
3
+ log/*.log
4
+ tmp/**/*
data/app/Gemfile ADDED
@@ -0,0 +1,27 @@
1
+ source 'http://rubygems.org'
2
+
3
+ gem 'rails', '3.0.0'
4
+ gem 'pg'
5
+ gem 'activerecord-postgres-hstore', '0.0.2'
6
+
7
+ # Use unicorn as the web server
8
+ # gem 'unicorn'
9
+
10
+ # Deploy with Capistrano
11
+ # gem 'capistrano'
12
+
13
+ # To use debugger
14
+ # gem 'ruby-debug'
15
+
16
+ # Bundle the extra gems:
17
+ # gem 'bj'
18
+ # gem 'nokogiri', '1.4.1'
19
+ # gem 'sqlite3-ruby', :require => 'sqlite3'
20
+ # gem 'aws-s3', :require => 'aws/s3'
21
+
22
+ # Bundle gems for the local environment. Make sure to
23
+ # put test-only gems in this group so their generators
24
+ # and rake tasks are available in development mode:
25
+ # group :development, :test do
26
+ # gem 'webrat'
27
+ # end
data/app/Gemfile.lock ADDED
@@ -0,0 +1,75 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ abstract (1.0.0)
5
+ actionmailer (3.0.0)
6
+ actionpack (= 3.0.0)
7
+ mail (~> 2.2.5)
8
+ actionpack (3.0.0)
9
+ activemodel (= 3.0.0)
10
+ activesupport (= 3.0.0)
11
+ builder (~> 2.1.2)
12
+ erubis (~> 2.6.6)
13
+ i18n (~> 0.4.1)
14
+ rack (~> 1.2.1)
15
+ rack-mount (~> 0.6.12)
16
+ rack-test (~> 0.5.4)
17
+ tzinfo (~> 0.3.23)
18
+ activemodel (3.0.0)
19
+ activesupport (= 3.0.0)
20
+ builder (~> 2.1.2)
21
+ i18n (~> 0.4.1)
22
+ activerecord (3.0.0)
23
+ activemodel (= 3.0.0)
24
+ activesupport (= 3.0.0)
25
+ arel (~> 1.0.0)
26
+ tzinfo (~> 0.3.23)
27
+ activerecord-postgres-hstore (0.0.2)
28
+ activeresource (3.0.0)
29
+ activemodel (= 3.0.0)
30
+ activesupport (= 3.0.0)
31
+ activesupport (3.0.0)
32
+ arel (1.0.1)
33
+ activesupport (~> 3.0.0)
34
+ builder (2.1.2)
35
+ erubis (2.6.6)
36
+ abstract (>= 1.0.0)
37
+ i18n (0.4.1)
38
+ mail (2.2.5)
39
+ activesupport (>= 2.3.6)
40
+ mime-types
41
+ treetop (>= 1.4.5)
42
+ mime-types (1.16)
43
+ pg (0.9.0)
44
+ polyglot (0.3.1)
45
+ rack (1.2.1)
46
+ rack-mount (0.6.13)
47
+ rack (>= 1.0.0)
48
+ rack-test (0.5.4)
49
+ rack (>= 1.0)
50
+ rails (3.0.0)
51
+ actionmailer (= 3.0.0)
52
+ actionpack (= 3.0.0)
53
+ activerecord (= 3.0.0)
54
+ activeresource (= 3.0.0)
55
+ activesupport (= 3.0.0)
56
+ bundler (~> 1.0.0)
57
+ railties (= 3.0.0)
58
+ railties (3.0.0)
59
+ actionpack (= 3.0.0)
60
+ activesupport (= 3.0.0)
61
+ rake (>= 0.8.4)
62
+ thor (~> 0.14.0)
63
+ rake (0.8.7)
64
+ thor (0.14.0)
65
+ treetop (1.4.8)
66
+ polyglot (>= 0.3.1)
67
+ tzinfo (0.3.23)
68
+
69
+ PLATFORMS
70
+ ruby
71
+
72
+ DEPENDENCIES
73
+ activerecord-postgres-hstore (= 0.0.2)
74
+ pg
75
+ rails (= 3.0.0)
data/app/README ADDED
@@ -0,0 +1,256 @@
1
+ == Welcome to Rails
2
+
3
+ Rails is a web-application framework that includes everything needed to create
4
+ database-backed web applications according to the Model-View-Control pattern.
5
+
6
+ This pattern splits the view (also called the presentation) into "dumb"
7
+ templates that are primarily responsible for inserting pre-built data in between
8
+ HTML tags. The model contains the "smart" domain objects (such as Account,
9
+ Product, Person, Post) that holds all the business logic and knows how to
10
+ persist themselves to a database. The controller handles the incoming requests
11
+ (such as Save New Account, Update Product, Show Post) by manipulating the model
12
+ and directing data to the view.
13
+
14
+ In Rails, the model is handled by what's called an object-relational mapping
15
+ layer entitled Active Record. This layer allows you to present the data from
16
+ database rows as objects and embellish these data objects with business logic
17
+ methods. You can read more about Active Record in
18
+ link:files/vendor/rails/activerecord/README.html.
19
+
20
+ The controller and view are handled by the Action Pack, which handles both
21
+ layers by its two parts: Action View and Action Controller. These two layers
22
+ are bundled in a single package due to their heavy interdependence. This is
23
+ unlike the relationship between the Active Record and Action Pack that is much
24
+ more separate. Each of these packages can be used independently outside of
25
+ Rails. You can read more about Action Pack in
26
+ link:files/vendor/rails/actionpack/README.html.
27
+
28
+
29
+ == Getting Started
30
+
31
+ 1. At the command prompt, create a new Rails application:
32
+ <tt>rails new myapp</tt> (where <tt>myapp</tt> is the application name)
33
+
34
+ 2. Change directory to <tt>myapp</tt> and start the web server:
35
+ <tt>cd myapp; rails server</tt> (run with --help for options)
36
+
37
+ 3. Go to http://localhost:3000/ and you'll see:
38
+ "Welcome aboard: You're riding Ruby on Rails!"
39
+
40
+ 4. Follow the guidelines to start developing your application. You can find
41
+ the following resources handy:
42
+
43
+ * The Getting Started Guide: http://guides.rubyonrails.org/getting_started.html
44
+ * Ruby on Rails Tutorial Book: http://www.railstutorial.org/
45
+
46
+
47
+ == Debugging Rails
48
+
49
+ Sometimes your application goes wrong. Fortunately there are a lot of tools that
50
+ will help you debug it and get it back on the rails.
51
+
52
+ First area to check is the application log files. Have "tail -f" commands
53
+ running on the server.log and development.log. Rails will automatically display
54
+ debugging and runtime information to these files. Debugging info will also be
55
+ shown in the browser on requests from 127.0.0.1.
56
+
57
+ You can also log your own messages directly into the log file from your code
58
+ using the Ruby logger class from inside your controllers. Example:
59
+
60
+ class WeblogController < ActionController::Base
61
+ def destroy
62
+ @weblog = Weblog.find(params[:id])
63
+ @weblog.destroy
64
+ logger.info("#{Time.now} Destroyed Weblog ID ##{@weblog.id}!")
65
+ end
66
+ end
67
+
68
+ The result will be a message in your log file along the lines of:
69
+
70
+ Mon Oct 08 14:22:29 +1000 2007 Destroyed Weblog ID #1!
71
+
72
+ More information on how to use the logger is at http://www.ruby-doc.org/core/
73
+
74
+ Also, Ruby documentation can be found at http://www.ruby-lang.org/. There are
75
+ several books available online as well:
76
+
77
+ * Programming Ruby: http://www.ruby-doc.org/docs/ProgrammingRuby/ (Pickaxe)
78
+ * Learn to Program: http://pine.fm/LearnToProgram/ (a beginners guide)
79
+
80
+ These two books will bring you up to speed on the Ruby language and also on
81
+ programming in general.
82
+
83
+
84
+ == Debugger
85
+
86
+ Debugger support is available through the debugger command when you start your
87
+ Mongrel or WEBrick server with --debugger. This means that you can break out of
88
+ execution at any point in the code, investigate and change the model, and then,
89
+ resume execution! You need to install ruby-debug to run the server in debugging
90
+ mode. With gems, use <tt>sudo gem install ruby-debug</tt>. Example:
91
+
92
+ class WeblogController < ActionController::Base
93
+ def index
94
+ @posts = Post.find(:all)
95
+ debugger
96
+ end
97
+ end
98
+
99
+ So the controller will accept the action, run the first line, then present you
100
+ with a IRB prompt in the server window. Here you can do things like:
101
+
102
+ >> @posts.inspect
103
+ => "[#<Post:0x14a6be8
104
+ @attributes={"title"=>nil, "body"=>nil, "id"=>"1"}>,
105
+ #<Post:0x14a6620
106
+ @attributes={"title"=>"Rails", "body"=>"Only ten..", "id"=>"2"}>]"
107
+ >> @posts.first.title = "hello from a debugger"
108
+ => "hello from a debugger"
109
+
110
+ ...and even better, you can examine how your runtime objects actually work:
111
+
112
+ >> f = @posts.first
113
+ => #<Post:0x13630c4 @attributes={"title"=>nil, "body"=>nil, "id"=>"1"}>
114
+ >> f.
115
+ Display all 152 possibilities? (y or n)
116
+
117
+ Finally, when you're ready to resume execution, you can enter "cont".
118
+
119
+
120
+ == Console
121
+
122
+ The console is a Ruby shell, which allows you to interact with your
123
+ application's domain model. Here you'll have all parts of the application
124
+ configured, just like it is when the application is running. You can inspect
125
+ domain models, change values, and save to the database. Starting the script
126
+ without arguments will launch it in the development environment.
127
+
128
+ To start the console, run <tt>rails console</tt> from the application
129
+ directory.
130
+
131
+ Options:
132
+
133
+ * Passing the <tt>-s, --sandbox</tt> argument will rollback any modifications
134
+ made to the database.
135
+ * Passing an environment name as an argument will load the corresponding
136
+ environment. Example: <tt>rails console production</tt>.
137
+
138
+ To reload your controllers and models after launching the console run
139
+ <tt>reload!</tt>
140
+
141
+ More information about irb can be found at:
142
+ link:http://www.rubycentral.com/pickaxe/irb.html
143
+
144
+
145
+ == dbconsole
146
+
147
+ You can go to the command line of your database directly through <tt>rails
148
+ dbconsole</tt>. You would be connected to the database with the credentials
149
+ defined in database.yml. Starting the script without arguments will connect you
150
+ to the development database. Passing an argument will connect you to a different
151
+ database, like <tt>rails dbconsole production</tt>. Currently works for MySQL,
152
+ PostgreSQL and SQLite 3.
153
+
154
+ == Description of Contents
155
+
156
+ The default directory structure of a generated Ruby on Rails application:
157
+
158
+ |-- app
159
+ | |-- controllers
160
+ | |-- helpers
161
+ | |-- models
162
+ | `-- views
163
+ | `-- layouts
164
+ |-- config
165
+ | |-- environments
166
+ | |-- initializers
167
+ | `-- locales
168
+ |-- db
169
+ |-- doc
170
+ |-- lib
171
+ | `-- tasks
172
+ |-- log
173
+ |-- public
174
+ | |-- images
175
+ | |-- javascripts
176
+ | `-- stylesheets
177
+ |-- script
178
+ | `-- performance
179
+ |-- test
180
+ | |-- fixtures
181
+ | |-- functional
182
+ | |-- integration
183
+ | |-- performance
184
+ | `-- unit
185
+ |-- tmp
186
+ | |-- cache
187
+ | |-- pids
188
+ | |-- sessions
189
+ | `-- sockets
190
+ `-- vendor
191
+ `-- plugins
192
+
193
+ app
194
+ Holds all the code that's specific to this particular application.
195
+
196
+ app/controllers
197
+ Holds controllers that should be named like weblogs_controller.rb for
198
+ automated URL mapping. All controllers should descend from
199
+ ApplicationController which itself descends from ActionController::Base.
200
+
201
+ app/models
202
+ Holds models that should be named like post.rb. Models descend from
203
+ ActiveRecord::Base by default.
204
+
205
+ app/views
206
+ Holds the template files for the view that should be named like
207
+ weblogs/index.html.erb for the WeblogsController#index action. All views use
208
+ eRuby syntax by default.
209
+
210
+ app/views/layouts
211
+ Holds the template files for layouts to be used with views. This models the
212
+ common header/footer method of wrapping views. In your views, define a layout
213
+ using the <tt>layout :default</tt> and create a file named default.html.erb.
214
+ Inside default.html.erb, call <% yield %> to render the view using this
215
+ layout.
216
+
217
+ app/helpers
218
+ Holds view helpers that should be named like weblogs_helper.rb. These are
219
+ generated for you automatically when using generators for controllers.
220
+ Helpers can be used to wrap functionality for your views into methods.
221
+
222
+ config
223
+ Configuration files for the Rails environment, the routing map, the database,
224
+ and other dependencies.
225
+
226
+ db
227
+ Contains the database schema in schema.rb. db/migrate contains all the
228
+ sequence of Migrations for your schema.
229
+
230
+ doc
231
+ This directory is where your application documentation will be stored when
232
+ generated using <tt>rake doc:app</tt>
233
+
234
+ lib
235
+ Application specific libraries. Basically, any kind of custom code that
236
+ doesn't belong under controllers, models, or helpers. This directory is in
237
+ the load path.
238
+
239
+ public
240
+ The directory available for the web server. Contains subdirectories for
241
+ images, stylesheets, and javascripts. Also contains the dispatchers and the
242
+ default HTML files. This should be set as the DOCUMENT_ROOT of your web
243
+ server.
244
+
245
+ script
246
+ Helper scripts for automation and generation.
247
+
248
+ test
249
+ Unit and functional tests along with fixtures. When using the rails generate
250
+ command, template test files will be generated for you and placed in this
251
+ directory.
252
+
253
+ vendor
254
+ External libraries that the application depends on. Also includes the plugins
255
+ subdirectory. If the app has frozen rails, those gems also go here, under
256
+ vendor/rails/. This directory is in the load path.