Skip to content
This repository
Browse code

first commit

  • Loading branch information...
commit ba1fb1d5af0c9ec21133edc7872d7daefd882080 0 parents
raul murciano authored June 06, 2008

Showing 106 changed files with 4,550 additions and 0 deletions. Show diff stats Hide diff stats

  1. 6  ChangeLog
  2. 20  MIT-LICENSE
  3. 149  README.rdoc
  4. 22  Rakefile
  5. 256  SampleApp/README
  6. 10  SampleApp/Rakefile
  7. 17  SampleApp/app/controllers/application.rb
  8. 85  SampleApp/app/controllers/users_controller.rb
  9. 3  SampleApp/app/helpers/application_helper.rb
  10. 2  SampleApp/app/helpers/users_helper.rb
  11. 2  SampleApp/app/models/user.rb
  12. 35  SampleApp/app/views/layouts/application.html.erb
  13. 22  SampleApp/app/views/users/edit.html.erb
  14. 22  SampleApp/app/views/users/index.html.erb
  15. 21  SampleApp/app/views/users/new.html.erb
  16. 13  SampleApp/app/views/users/show.html.erb
  17. 109  SampleApp/config/boot.rb
  18. 19  SampleApp/config/database.yml
  19. 67  SampleApp/config/environment.rb
  20. 17  SampleApp/config/environments/development.rb
  21. 22  SampleApp/config/environments/production.rb
  22. 22  SampleApp/config/environments/test.rb
  23. 10  SampleApp/config/initializers/inflections.rb
  24. 5  SampleApp/config/initializers/mime_types.rb
  25. 15  SampleApp/config/initializers/new_rails_defaults.rb
  26. 14  SampleApp/config/routes.rb
  27. 0  SampleApp/config/routes_en.yml
  28. 4  SampleApp/config/routes_es.yml
  29. BIN  SampleApp/db/development.sqlite3
  30. 14  SampleApp/db/migrate/20080606095256_create_users.rb
  31. 21  SampleApp/db/schema.rb
  32. BIN  SampleApp/db/test.sqlite3
  33. 2  SampleApp/doc/README_FOR_APP
  34. 14  SampleApp/lang/es.yml
  35. 30  SampleApp/public/404.html
  36. 30  SampleApp/public/422.html
  37. 30  SampleApp/public/500.html
  38. 10  SampleApp/public/dispatch.cgi
  39. 24  SampleApp/public/dispatch.fcgi
  40. 10  SampleApp/public/dispatch.rb
  41. 54  SampleApp/public/stylesheets/scaffold.css
  42. 3  SampleApp/script/about
  43. 3  SampleApp/script/console
  44. 3  SampleApp/script/dbconsole
  45. 3  SampleApp/script/destroy
  46. 3  SampleApp/script/generate
  47. 3  SampleApp/script/performance/benchmarker
  48. 3  SampleApp/script/performance/profiler
  49. 3  SampleApp/script/performance/request
  50. 3  SampleApp/script/plugin
  51. 3  SampleApp/script/process/inspector
  52. 3  SampleApp/script/process/reaper
  53. 3  SampleApp/script/process/spawner
  54. 3  SampleApp/script/runner
  55. 3  SampleApp/script/server
  56. 9  SampleApp/test/fixtures/users.yml
  57. 45  SampleApp/test/functional/users_controller_test.rb
  58. 55  SampleApp/test/test_helper.rb
  59. 8  SampleApp/test/unit/user_test.rb
  60. 18  SampleApp/vendor/plugins/gibberish/LICENSE
  61. 118  SampleApp/vendor/plugins/gibberish/README
  62. 14  SampleApp/vendor/plugins/gibberish/Rakefile
  63. 3  SampleApp/vendor/plugins/gibberish/init.rb
  64. 3  SampleApp/vendor/plugins/gibberish/lang/es.yml
  65. 3  SampleApp/vendor/plugins/gibberish/lang/fr.yml
  66. 8  SampleApp/vendor/plugins/gibberish/lib/gibberish.rb
  67. 88  SampleApp/vendor/plugins/gibberish/lib/gibberish/localize.rb
  68. 17  SampleApp/vendor/plugins/gibberish/lib/gibberish/string_ext.rb
  69. 203  SampleApp/vendor/plugins/gibberish/test/gibberish_test.rb
  70. 1  SampleApp/vendor/plugins/gibberish/test/lang/es.yml
  71. 1  SampleApp/vendor/plugins/gibberish/test/lang/fr.yml
  72. 6  SampleApp/vendor/plugins/translate_routes/ChangeLog
  73. 20  SampleApp/vendor/plugins/translate_routes/MIT-LICENSE
  74. 150  SampleApp/vendor/plugins/translate_routes/README
  75. 22  SampleApp/vendor/plugins/translate_routes/Rakefile
  76. 0  SampleApp/vendor/plugins/translate_routes/config/routes_en.yml
  77. 1  SampleApp/vendor/plugins/translate_routes/config/routes_es.yml
  78. 1  SampleApp/vendor/plugins/translate_routes/doc/created.rid
  79. 351  SampleApp/vendor/plugins/translate_routes/doc/files/README.html
  80. 26  SampleApp/vendor/plugins/translate_routes/doc/fr_class_index.html
  81. 27  SampleApp/vendor/plugins/translate_routes/doc/fr_file_index.html
  82. 26  SampleApp/vendor/plugins/translate_routes/doc/fr_method_index.html
  83. 24  SampleApp/vendor/plugins/translate_routes/doc/index.html
  84. 208  SampleApp/vendor/plugins/translate_routes/doc/rdoc-style.css
  85. 1  SampleApp/vendor/plugins/translate_routes/init.rb
  86. 1  SampleApp/vendor/plugins/translate_routes/install.rb
  87. 172  SampleApp/vendor/plugins/translate_routes/lib/translate_routes.rb
  88. 4  SampleApp/vendor/plugins/translate_routes/tasks/translate_routes_tasks.rake
  89. 222  SampleApp/vendor/plugins/translate_routes/test/translate_routes_test.rb
  90. 1  SampleApp/vendor/plugins/translate_routes/uninstall.rb
  91. 0  config/routes_en.yml
  92. 1  config/routes_es.yml
  93. 1  doc/created.rid
  94. 351  doc/files/README.html
  95. 358  doc/files/README_rdoc.html
  96. 26  doc/fr_class_index.html
  97. 27  doc/fr_file_index.html
  98. 26  doc/fr_method_index.html
  99. 24  doc/index.html
  100. 208  doc/rdoc-style.css
  101. 1  init.rb
  102. 1  install.rb
  103. 172  lib/translate_routes.rb
  104. 4  tasks/translate_routes_tasks.rake
  105. 222  test/translate_routes_test.rb
  106. 1  uninstall.rb
6  ChangeLog
... ...
@@ -0,0 +1,6 @@
  1
+-- 0.95 (Jan 21st 2008)
  2
+  * Still beta version
  3
+  * Added yaml files support for dictionaries
  4
+
  5
+-- 0.9 (Dec 27th 2007)
  6
+  * Beta version
20  MIT-LICENSE
... ...
@@ -0,0 +1,20 @@
  1
+Copyright (c) 2007 Raul Murciano [http://raul.murciano.net], Domestika INTERNET S.L. [http://domestika.org]
  2
+
  3
+Permission is hereby granted, free of charge, to any person obtaining
  4
+a copy of this software and associated documentation files (the
  5
+"Software"), to deal in the Software without restriction, including
  6
+without limitation the rights to use, copy, modify, merge, publish,
  7
+distribute, sublicense, and/or sell copies of the Software, and to
  8
+permit persons to whom the Software is furnished to do so, subject to
  9
+the following conditions:
  10
+
  11
+The above copyright notice and this permission notice shall be
  12
+included in all copies or substantial portions of the Software.
  13
+
  14
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  15
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  16
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  17
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  18
+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  19
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  20
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
149  README.rdoc
Source Rendered
... ...
@@ -0,0 +1,149 @@
  1
+=TranslateRoutes
  2
+This Rails plugin provides a simple way to translate your URLs to any number of languages.
  3
+All routes automatically add a <tt>:lang</tt> parameter to the request so your controllers can setup an internationalized user experience.
  4
+
  5
+The plugin has been designed to be easy to use and customize. 
  6
+As it works after routing processing, it plays nice with all kind of routing definitions, including RESTful and named routes.
  7
+It also takes care of your current routing helpers by translating them transparently.
  8
+
  9
+==Installation
  10
+Just check it out on your app's <tt>/vendor/plugins</tt> and see the examples below.
  11
+
  12
+==Usage
  13
+Let's start with a tiny example. Of course you need to define your routes first, e.g:
  14
+
  15
+	ActionController::Routing::Routes.draw do |map| 
  16
+	  map.connect 'contact', :controller => 'contact', :action => 'index'
  17
+	end
  18
+
  19
+After that, on the same routes.rb file, you can translate the generated route by doing:
  20
+
  21
+	ActionController::Routing::Translator.translate do |t|
  22
+	  t['es'] = {
  23
+	    'contact' => 'contacto'
  24
+	  }
  25
+	end
  26
+
  27
+This will give you the next routes (check it out by doing 'rake routes'):
  28
+
  29
+	/es/contacto {:lang=>"es", :controller=>"contact", :action=>"index"}
  30
+	/contact     {:lang=>"en", :controller=>"contact", :action=>"index"}
  31
+
  32
+As you can see:
  33
+- a +lang+ param has been added to your routes, with the value of the used language (*)
  34
+- +en+ is the default language (*)
  35
+- the URLs associated with a language are always prefixed with the language code that you provided on the translation.
  36
+- the default language URLs have no language prefix (*)
  37
+(*) You can customize this behaviour, see "Configuration" below.
  38
+
  39
+Let's add some routes and translations to our example:
  40
+
  41
+	ActionController::Routing::Routes.draw do |map| 
  42
+	  map.connect 'contact', :controller => 'contact', :action => 'index'
  43
+	  map.home '', :controller => 'main', :action => 'index'
  44
+	  map.resources :people
  45
+	end
  46
+	
  47
+	ActionController::Routing::Translator.translate do |t|
  48
+
  49
+	  t['es'] = {
  50
+	    'contact' => 'contacto',
  51
+	    'people' => 'gente',
  52
+			'new' => 'crear',
  53
+			'edit' =>'editar'
  54
+		}
  55
+
  56
+	  t['fr'] = {
  57
+			'people' => 'personne',
  58
+			'new' => 'neuf'
  59
+		}
  60
+	end
  61
+
  62
+Again, you can use <tt>rake routes</tt> to see the generated URLs. I'll only talk about some of them:
  63
+
  64
+We didn't give any french translation for +contact+, so the french associated URLs use the untranslated text:
  65
+
  66
+	/fr/contact                   {:lang=>"fr", :controller=>"contact", :action=>"index"}
  67
+	/es/contacto                  {:lang=>"es", :controller=>"contact", :action=>"index"}
  68
+	/contact                      {:lang=>"en", :controller=>"contact", :action=>"index"}
  69
+
  70
+The named routes have generated not only translated URLs but also a helper for each language:
  71
+
  72
+	home_fr        /fr                           {:lang=>"fr", :controller=>"main", :action=>"index"}
  73
+	home_es        /es                           {:lang=>"es", :controller=>"main", :action=>"index"}
  74
+	home_en        /                             {:lang=>"en", :controller=>"main", :action=>"index"}
  75
+
  76
+This means that you can use +home_es_path+ and +home_es_url+ on your controllers and views.
  77
+
  78
+No +home+ named route is shown on the list so it looks like you can't use a simple +home_path+ helper, but relax: you have a +home_path+ helper available for your controllers and views. It looks for the current +lang+ value and redirects to the appropiate helper. This means that if you're rendering the <tt>contact/index</tt> view when visiting <tt>/es/contacto</tt>, the +home_path+ helper will call to +home_es_path+ and return its result. The same applies to +home_url+, obviously.
  79
+
  80
+We can see that resource controllers and actions are translated as well:
  81
+
  82
+	new_person_fr GET   /fr/personne/neuf             {:lang=>"fr", :controller=>"people", :action=>"new"}
  83
+	new_person_es GET   /es/gente/crear               {:lang=>"es", :controller=>"people", :action=>"new"}
  84
+	new_person GET    	/people/new                   {:lang=>"en", :controller=>"people", :action=>"new"}
  85
+
  86
+We can get rid of that verbose translation hashes by using yaml files. Create a file inside your <tt>/config</tt> directory, called <tt>routes_es.yml</tt> and fill it with your desired translations, e.g:
  87
+
  88
+	# /config/routes_es.yml
  89
+	person: persona
  90
+
  91
+and replace all the
  92
+
  93
+	ActionController::Routing::Translator.translate do  
  94
+		... 
  95
+	end
  96
+
  97
+stuff on <tt>routes.rb</tt> with this simple line:
  98
+
  99
+	ActionController::Routing::Translator.translate_from_files
  100
+
  101
+== Integration
  102
+You can find a sample Rails application on the translate_routes repository, designed to show how easy is to setup 
  103
+
  104
+== Configuration
  105
+You can customize some features by adding some lines before your translation code:
  106
+
  107
+- You can change the language param key (<tt>:lang</tt> by default). To change this feature use:
  108
+
  109
+	ActionController::Routing::Translator.lang_param_key = :foo
  110
+
  111
+This key should have the same name that the instance variable which keeps the language code on your controllers and views.
  112
+
  113
+- You can change the default language of your application with:
  114
+
  115
+	ActionController::Routing::Translator.default_lang = 'es'
  116
+
  117
+Of course, you can also translate your default language. If, as I do, all your controllers and actions have english names, you can have an english version on your site for free by doing:
  118
+
  119
+	ActionController::Routing::Translator.default_lang = 'es'
  120
+	ActionController::Routing::Translator.translate do |t|
  121
+	  t['en'] = {}
  122
+	  t['es'] = { # spanish translation	here }
  123
+	end
  124
+
  125
+or adding the equivalent <tt>/config/routes_es.yml</tt> and an empty <tt>/config/routes_en.yml</tt>
  126
+
  127
+- You can add a prefix also on your default language routes by doing:
  128
+
  129
+	ActionController::Routing::Translator.prefix_on_default_lang = true
  130
+
  131
+<b>WARNING!</b> this way you'll disable your root -empty- route: if english is your default language, your empty route will be translated to <tt>/en</tt> so you must manually take care of it.
  132
+
  133
+== Suggestions, bug reports, questions
  134
+Feedback and comments will be always welcome at raul@murciano.net
  135
+
  136
+
  137
+== Credits
  138
+- Raul Murciano [http://raul.murciano.net] - code
  139
+- Domestika INTERNET S.L [http://domestika.org] - incredible support, really nice people to work with!
  140
+
  141
+
  142
+== Rails routing resources
  143
+- David Black's 'Rails Routing' ebook rocks! - 'Ruby for Rails' too, BTW.
  144
+- Obie Fernandez's 'The Rails Way' - the definitive RoR reference, great work Obie!
  145
+
  146
+== License
  147
+Copyright (c) 2007
  148
+Raul Murciano [http://raul.murciano.net]
  149
+Domestika INTERNET S.L. [http://domestika.org], released under the MIT license (see MIT-LICENSE)
22  Rakefile
... ...
@@ -0,0 +1,22 @@
  1
+require 'rake'
  2
+require 'rake/testtask'
  3
+require 'rake/rdoctask'
  4
+
  5
+desc 'Default: run unit tests.'
  6
+task :default => :test
  7
+
  8
+desc 'Test the translate_routes plugin.'
  9
+Rake::TestTask.new(:test) do |t|
  10
+  t.libs << 'lib'
  11
+  t.pattern = 'test/**/*_test.rb'
  12
+  t.verbose = true
  13
+end
  14
+
  15
+desc 'Generate documentation for the translate_routes plugin.'
  16
+Rake::RDocTask.new(:rdoc) do |rdoc|
  17
+  rdoc.rdoc_dir = 'rdoc'
  18
+  rdoc.title    = 'TranslateRoutes'
  19
+  rdoc.options << '--line-numbers' << '--inline-source'
  20
+  rdoc.rdoc_files.include('README')
  21
+  rdoc.rdoc_files.include('lib/**/*.rb')
  22
+end
256  SampleApp/README
... ...
@@ -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" templates
  7
+that are primarily responsible for inserting pre-built data in between HTML tags.
  8
+The model contains the "smart" domain objects (such as Account, Product, Person,
  9
+Post) that holds all the business logic and knows how to persist themselves to
  10
+a database. The controller handles the incoming requests (such as Save New Account,
  11
+Update Product, Show Post) by manipulating the model and directing data to the view.
  12
+
  13
+In Rails, the model is handled by what's called an object-relational mapping
  14
+layer entitled Active Record. This layer allows you to present the data from
  15
+database rows as objects and embellish these data objects with business logic
  16
+methods. You can read more about Active Record in
  17
+link:files/vendor/rails/activerecord/README.html.
  18
+
  19
+The controller and view are handled by the Action Pack, which handles both
  20
+layers by its two parts: Action View and Action Controller. These two layers
  21
+are bundled in a single package due to their heavy interdependence. This is
  22
+unlike the relationship between the Active Record and Action Pack that is much
  23
+more separate. Each of these packages can be used independently outside of
  24
+Rails.  You can read more about Action Pack in
  25
+link:files/vendor/rails/actionpack/README.html.
  26
+
  27
+
  28
+== Getting Started
  29
+
  30
+1. At the command prompt, start a new Rails application using the <tt>rails</tt> command
  31
+   and your application name. Ex: rails myapp
  32
+2. Change directory into myapp and start the web server: <tt>script/server</tt> (run with --help for options)
  33
+3. Go to http://localhost:3000/ and get "Welcome aboard: You're riding the Rails!"
  34
+4. Follow the guidelines to start developing your application
  35
+
  36
+
  37
+== Web Servers
  38
+
  39
+By default, Rails will try to use Mongrel and lighttpd if they are installed, otherwise
  40
+Rails will use WEBrick, the webserver that ships with Ruby. When you run script/server,
  41
+Rails will check if Mongrel exists, then lighttpd and finally fall back to WEBrick. This ensures
  42
+that you can always get up and running quickly.
  43
+
  44
+Mongrel is a Ruby-based webserver with a C component (which requires compilation) that is
  45
+suitable for development and deployment of Rails applications. If you have Ruby Gems installed,
  46
+getting up and running with mongrel is as easy as: <tt>gem install mongrel</tt>.
  47
+More info at: http://mongrel.rubyforge.org
  48
+
  49
+If Mongrel is not installed, Rails will look for lighttpd. It's considerably faster than
  50
+Mongrel and WEBrick and also suited for production use, but requires additional
  51
+installation and currently only works well on OS X/Unix (Windows users are encouraged
  52
+to start with Mongrel). We recommend version 1.4.11 and higher. You can download it from
  53
+http://www.lighttpd.net.
  54
+
  55
+And finally, if neither Mongrel or lighttpd are installed, Rails will use the built-in Ruby
  56
+web server, WEBrick. WEBrick is a small Ruby web server suitable for development, but not
  57
+for production.
  58
+
  59
+But of course its also possible to run Rails on any platform that supports FCGI.
  60
+Apache, LiteSpeed, IIS are just a few. For more information on FCGI,
  61
+please visit: http://wiki.rubyonrails.com/rails/pages/FastCGI
  62
+
  63
+
  64
+== Apache .htaccess example
  65
+
  66
+# General Apache options
  67
+AddHandler fastcgi-script .fcgi
  68
+AddHandler cgi-script .cgi
  69
+Options +FollowSymLinks +ExecCGI
  70
+
  71
+# If you don't want Rails to look in certain directories,
  72
+# use the following rewrite rules so that Apache won't rewrite certain requests
  73
+# 
  74
+# Example:
  75
+#   RewriteCond %{REQUEST_URI} ^/notrails.*
  76
+#   RewriteRule .* - [L]
  77
+
  78
+# Redirect all requests not available on the filesystem to Rails
  79
+# By default the cgi dispatcher is used which is very slow
  80
+# 
  81
+# For better performance replace the dispatcher with the fastcgi one
  82
+#
  83
+# Example:
  84
+#   RewriteRule ^(.*)$ dispatch.fcgi [QSA,L]
  85
+RewriteEngine On
  86
+
  87
+# If your Rails application is accessed via an Alias directive,
  88
+# then you MUST also set the RewriteBase in this htaccess file.
  89
+#
  90
+# Example:
  91
+#   Alias /myrailsapp /path/to/myrailsapp/public
  92
+#   RewriteBase /myrailsapp
  93
+
  94
+RewriteRule ^$ index.html [QSA]
  95
+RewriteRule ^([^.]+)$ $1.html [QSA]
  96
+RewriteCond %{REQUEST_FILENAME} !-f
  97
+RewriteRule ^(.*)$ dispatch.cgi [QSA,L]
  98
+
  99
+# In case Rails experiences terminal errors
  100
+# Instead of displaying this message you can supply a file here which will be rendered instead
  101
+# 
  102
+# Example:
  103
+#   ErrorDocument 500 /500.html
  104
+
  105
+ErrorDocument 500 "<h2>Application error</h2>Rails application failed to start properly"
  106
+
  107
+
  108
+== Debugging Rails
  109
+
  110
+Sometimes your application goes wrong.  Fortunately there are a lot of tools that
  111
+will help you debug it and get it back on the rails.
  112
+
  113
+First area to check is the application log files.  Have "tail -f" commands running
  114
+on the server.log and development.log. Rails will automatically display debugging
  115
+and runtime information to these files. Debugging info will also be shown in the
  116
+browser on requests from 127.0.0.1.
  117
+
  118
+You can also log your own messages directly into the log file from your code using
  119
+the Ruby logger class from inside your controllers. Example:
  120
+
  121
+  class WeblogController < ActionController::Base
  122
+    def destroy
  123
+      @weblog = Weblog.find(params[:id])
  124
+      @weblog.destroy
  125
+      logger.info("#{Time.now} Destroyed Weblog ID ##{@weblog.id}!")
  126
+    end
  127
+  end
  128
+
  129
+The result will be a message in your log file along the lines of:
  130
+
  131
+  Mon Oct 08 14:22:29 +1000 2007 Destroyed Weblog ID #1
  132
+
  133
+More information on how to use the logger is at http://www.ruby-doc.org/core/
  134
+
  135
+Also, Ruby documentation can be found at http://www.ruby-lang.org/ including:
  136
+
  137
+* The Learning Ruby (Pickaxe) Book: http://www.ruby-doc.org/docs/ProgrammingRuby/
  138
+* Learn to Program: http://pine.fm/LearnToProgram/  (a beginners guide)
  139
+
  140
+These two online (and free) books will bring you up to speed on the Ruby language
  141
+and also on programming in general.
  142
+
  143
+
  144
+== Debugger
  145
+
  146
+Debugger support is available through the debugger command when you start your Mongrel or
  147
+Webrick server with --debugger. This means that you can break out of execution at any point
  148
+in the code, investigate and change the model, AND then resume execution! 
  149
+You need to install ruby-debug to run the server in debugging mode. With gems, use 'gem install ruby-debug'
  150
+Example:
  151
+
  152
+  class WeblogController < ActionController::Base
  153
+    def index
  154
+      @posts = Post.find(:all)
  155
+      debugger
  156
+    end
  157
+  end
  158
+
  159
+So the controller will accept the action, run the first line, then present you
  160
+with a IRB prompt in the server window. Here you can do things like:
  161
+
  162
+  >> @posts.inspect
  163
+  => "[#<Post:0x14a6be8 @attributes={\"title\"=>nil, \"body\"=>nil, \"id\"=>\"1\"}>,
  164
+       #<Post:0x14a6620 @attributes={\"title\"=>\"Rails you know!\", \"body\"=>\"Only ten..\", \"id\"=>\"2\"}>]"
  165
+  >> @posts.first.title = "hello from a debugger"
  166
+  => "hello from a debugger"
  167
+
  168
+...and even better is that you can examine how your runtime objects actually work:
  169
+
  170
+  >> f = @posts.first
  171
+  => #<Post:0x13630c4 @attributes={"title"=>nil, "body"=>nil, "id"=>"1"}>
  172
+  >> f.
  173
+  Display all 152 possibilities? (y or n)
  174
+
  175
+Finally, when you're ready to resume execution, you enter "cont"
  176
+
  177
+
  178
+== Console
  179
+
  180
+You can interact with the domain model by starting the console through <tt>script/console</tt>.
  181
+Here you'll have all parts of the application configured, just like it is when the
  182
+application is running. You can inspect domain models, change values, and save to the
  183
+database. Starting the script without arguments will launch it in the development environment.
  184
+Passing an argument will specify a different environment, like <tt>script/console production</tt>.
  185
+
  186
+To reload your controllers and models after launching the console run <tt>reload!</tt>
  187
+
  188
+== dbconsole
  189
+
  190
+You can go to the command line of your database directly through <tt>script/dbconsole</tt>.
  191
+You would be connected to the database with the credentials defined in database.yml.
  192
+Starting the script without arguments will connect you to the development database. Passing an
  193
+argument will connect you to a different database, like <tt>script/dbconsole production</tt>.
  194
+Currently works for mysql, postgresql and sqlite.
  195
+
  196
+== Description of Contents
  197
+
  198
+app
  199
+  Holds all the code that's specific to this particular application.
  200
+
  201
+app/controllers
  202
+  Holds controllers that should be named like weblogs_controller.rb for
  203
+  automated URL mapping. All controllers should descend from ApplicationController
  204
+  which itself descends from ActionController::Base.
  205
+
  206
+app/models
  207
+  Holds models that should be named like post.rb.
  208
+  Most models will descend from ActiveRecord::Base.
  209
+
  210
+app/views
  211
+  Holds the template files for the view that should be named like
  212
+  weblogs/index.html.erb for the WeblogsController#index action. All views use eRuby
  213
+  syntax.
  214
+
  215
+app/views/layouts
  216
+  Holds the template files for layouts to be used with views. This models the common
  217
+  header/footer method of wrapping views. In your views, define a layout using the
  218
+  <tt>layout :default</tt> and create a file named default.html.erb. Inside default.html.erb,
  219
+  call <% yield %> to render the view using this layout.
  220
+
  221
+app/helpers
  222
+  Holds view helpers that should be named like weblogs_helper.rb. These are generated
  223
+  for you automatically when using script/generate for controllers. Helpers can be used to
  224
+  wrap functionality for your views into methods.
  225
+
  226
+config
  227
+  Configuration files for the Rails environment, the routing map, the database, and other dependencies.
  228
+
  229
+db
  230
+  Contains the database schema in schema.rb.  db/migrate contains all
  231
+  the sequence of Migrations for your schema.
  232
+
  233
+doc
  234
+  This directory is where your application documentation will be stored when generated
  235
+  using <tt>rake doc:app</tt>
  236
+
  237
+lib
  238
+  Application specific libraries. Basically, any kind of custom code that doesn't
  239
+  belong under controllers, models, or helpers. This directory is in the load path.
  240
+
  241
+public
  242
+  The directory available for the web server. Contains subdirectories for images, stylesheets,
  243
+  and javascripts. Also contains the dispatchers and the default HTML files. This should be
  244
+  set as the DOCUMENT_ROOT of your web server.
  245
+
  246
+script
  247
+  Helper scripts for automation and generation.
  248
+
  249
+test
  250
+  Unit and functional tests along with fixtures. When using the script/generate scripts, template
  251
+  test files will be generated for you and placed in this directory.
  252
+
  253
+vendor
  254
+  External libraries that the application depends on. Also includes the plugins subdirectory.
  255
+  If the app has frozen rails, those gems also go here, under vendor/rails/.
  256
+  This directory is in the load path.
10  SampleApp/Rakefile
... ...
@@ -0,0 +1,10 @@
  1
+# Add your own tasks in files placed in lib/tasks ending in .rake,
  2
+# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
  3
+
  4
+require(File.join(File.dirname(__FILE__), 'config', 'boot'))
  5
+
  6
+require 'rake'
  7
+require 'rake/testtask'
  8
+require 'rake/rdoctask'
  9
+
  10
+require 'tasks/rails'
17  SampleApp/app/controllers/application.rb
... ...
@@ -0,0 +1,17 @@
  1
+# Filters added to this controller apply to all controllers in the application.
  2
+# Likewise, all the methods added will be available for all controllers.
  3
+
  4
+class ApplicationController < ActionController::Base
  5
+
  6
+  before_filter :set_language
  7
+  
  8
+  private
  9
+
  10
+  def set_language
  11
+    @lang = params[ActionController::Routing::Translator.lang_param_key] || ActionController::Routing::Translator.default_lang
  12
+    default_url_options ActionController::Routing::Translator => @lang
  13
+
  14
+    Gibberish.current_language = @lang.to_sym # If you use the Gibberish plugin to translate strings
  15
+  end
  16
+  
  17
+end
85  SampleApp/app/controllers/users_controller.rb
... ...
@@ -0,0 +1,85 @@
  1
+class UsersController < ApplicationController
  2
+  # GET /users
  3
+  # GET /users.xml
  4
+  def index
  5
+    @users = User.find(:all)
  6
+
  7
+    respond_to do |format|
  8
+      format.html # index.html.erb
  9
+      format.xml  { render :xml => @users }
  10
+    end
  11
+  end
  12
+
  13
+  # GET /users/1
  14
+  # GET /users/1.xml
  15
+  def show
  16
+    @user = User.find(params[:id])
  17
+
  18
+    respond_to do |format|
  19
+      format.html # show.html.erb
  20
+      format.xml  { render :xml => @user }
  21
+    end
  22
+  end
  23
+
  24
+  # GET /users/new
  25
+  # GET /users/new.xml
  26
+  def new
  27
+    @user = User.new
  28
+
  29
+    respond_to do |format|
  30
+      format.html # new.html.erb
  31
+      format.xml  { render :xml => @user }
  32
+    end
  33
+  end
  34
+
  35
+  # GET /users/1/edit
  36
+  def edit
  37
+    @user = User.find(params[:id])
  38
+  end
  39
+
  40
+  # POST /users
  41
+  # POST /users.xml
  42
+  def create
  43
+    @user = User.new(params[:user])
  44
+
  45
+    respond_to do |format|
  46
+      if @user.save
  47
+        flash[:notice] = 'User was successfully created.'[:User_was_successfully_created]
  48
+        format.html { redirect_to(@user) }
  49
+        format.xml  { render :xml => @user, :status => :created, :location => @user }
  50
+      else
  51
+        format.html { render :action => "new" }
  52
+        format.xml  { render :xml => @user.errors, :status => :unprocessable_entity }
  53
+      end
  54
+    end
  55
+  end
  56
+
  57
+  # PUT /users/1
  58
+  # PUT /users/1.xml
  59
+  def update
  60
+    @user = User.find(params[:id])
  61
+
  62
+    respond_to do |format|
  63
+      if @user.update_attributes(params[:user])
  64
+        flash[:notice] = 'User was successfully updated.'[:User_was_successfully_updated]
  65
+        format.html { redirect_to(@user) }
  66
+        format.xml  { head :ok }
  67
+      else
  68
+        format.html { render :action => "edit" }
  69
+        format.xml  { render :xml => @user.errors, :status => :unprocessable_entity }
  70
+      end
  71
+    end
  72
+  end
  73
+
  74
+  # DELETE /users/1
  75
+  # DELETE /users/1.xml
  76
+  def destroy
  77
+    @user = User.find(params[:id])
  78
+    @user.destroy
  79
+
  80
+    respond_to do |format|
  81
+      format.html { redirect_to(users_url) }
  82
+      format.xml  { head :ok }
  83
+    end
  84
+  end
  85
+end
3  SampleApp/app/helpers/application_helper.rb
... ...
@@ -0,0 +1,3 @@
  1
+# Methods added to this helper will be available to all templates in the application.
  2
+module ApplicationHelper
  3
+end
2  SampleApp/app/helpers/users_helper.rb
... ...
@@ -0,0 +1,2 @@
  1
+module UsersHelper
  2
+end
2  SampleApp/app/models/user.rb
... ...
@@ -0,0 +1,2 @@
  1
+class User < ActiveRecord::Base
  2
+end
35  SampleApp/app/views/layouts/application.html.erb
... ...
@@ -0,0 +1,35 @@
  1
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  2
+       "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  3
+
  4
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  5
+<head>
  6
+  <meta http-equiv="content-type" content="text/html;charset=UTF-8" />
  7
+  <title>Sample translate routes application</title>
  8
+  <%= stylesheet_link_tag 'scaffold' %>
  9
+</head>
  10
+<body>
  11
+<p>
  12
+	This is a sample application to show how easily you can integrate the translate routes plugin to your Rails applications.
  13
+	The key points are located on:</p>
  14
+	<ul>
  15
+		<li><strong>/config/routes.rb</strong>: you can see how to add translation to your defined routes</li>
  16
+		<li><strong>/app/controllers/application.rb</strong>: it shows an example of how to set the language from the URL. You could also set the language from current user profiles, etc.</li>
  17
+		<li><strong>/app/views/layouts/application.html.erb</strong>: here you can see some routing helpers in action:
  18
+			<ul>
  19
+				<li><%= link_to 'a link based on the current language', users_path %></li>
  20
+				<li><%= link_to 'a link to an english URL', users_en_path %></li>
  21
+				<li><%= link_to 'a link to an spanish URL', users_es_path %></li>
  22
+			</ul>
  23
+		</li>		
  24
+		<li><strong>/test/test_helper.rb</strong>: includes some code to include a default language parameter to your functional and integration tests</li>		
  25
+	</ul>
  26
+<p>The application is a simple users CRUD and includes the gibberish plugin to translate all the user interface strings.</p>	
  27
+
  28
+<p style="color: green"><%= flash[:notice] %></p>
  29
+
  30
+<%= @lang == 'es' ? link_to('English version', :lang => 'en') : link_to('Spanish version', :lang => 'es') %>
  31
+
  32
+<%= yield  %>
  33
+
  34
+</body>
  35
+</html>
22  SampleApp/app/views/users/edit.html.erb
... ...
@@ -0,0 +1,22 @@
  1
+<h1><%= 'Editing user'[:Editing_user] %></h1>
  2
+
  3
+<% form_for(@user) do |f| %>
  4
+  <%= f.error_messages %>
  5
+
  6
+  <p>
  7
+		<%= 'Name'[:Name] %>
  8
+    <br />
  9
+    <%= f.text_field :name %>
  10
+  </p>
  11
+  <p>
  12
+		<%= 'Last Name'[:Last_Name] %>
  13
+    <br />
  14
+    <%= f.text_field :last_name %>
  15
+  </p>
  16
+  <p>
  17
+    <%= f.submit "Update"[:Update] %>
  18
+  </p>
  19
+<% end %>
  20
+
  21
+<%= link_to 'Show'[:Show], @user %> |
  22
+<%= link_to 'Back'[:Back], users_path %>
22  SampleApp/app/views/users/index.html.erb
... ...
@@ -0,0 +1,22 @@
  1
+<h1><%= 'Listing users'[:Listing_users] %></h1>
  2
+
  3
+<table>
  4
+  <tr>
  5
+    <th><%= 'Name'[:Name] %></th>
  6
+    <th><%= 'Last Name'[:Last_Name] %></th>
  7
+  </tr>
  8
+
  9
+<% for user in @users %>
  10
+  <tr>
  11
+    <td><%=h user.name %></td>
  12
+    <td><%=h user.last_name %></td>
  13
+    <td><%= link_to 'Show'[:Show], user %></td>
  14
+    <td><%= link_to 'Edit'[:Edit], edit_user_path(user) %></td>
  15
+    <td><%= link_to 'Destroy'[:Destroy], user, :confirm => 'Are you sure?'[:Are_you_sure], :method => :delete %></td>
  16
+  </tr>
  17
+<% end %>
  18
+</table>
  19
+
  20
+<br />
  21
+
  22
+<%= link_to 'New user'[:New_user], new_user_path %>
21  SampleApp/app/views/users/new.html.erb
... ...
@@ -0,0 +1,21 @@
  1
+<h1><%= 'New user'[:New_user] %></h1>
  2
+
  3
+<% form_for(@user) do |f| %>
  4
+  <%= f.error_messages %>
  5
+
  6
+  <p>
  7
+		<%= 'Name'[:Name] %>
  8
+    <br />
  9
+    <%= f.text_field :name %>
  10
+  </p>
  11
+  <p>
  12
+		<%= 'Last Name'[:Last_Name] %>
  13
+    <br />
  14
+    <%= f.text_field :last_name %>
  15
+  </p>
  16
+  <p>
  17
+    <%= f.submit "Create"[:Create] %>
  18
+  </p>
  19
+<% end %>
  20
+
  21
+<%= link_to 'Back'[:Back], users_path %>
13  SampleApp/app/views/users/show.html.erb
... ...
@@ -0,0 +1,13 @@
  1
+<p>
  2
+  <b><%= 'Name'[:Name] %></b>
  3
+  <%=h @user.name %>
  4
+</p>
  5
+
  6
+<p>
  7
+  <b><%= 'Last Name'[:Last_Name] %></b>
  8
+  <%=h @user.last_name %>
  9
+</p>
  10
+
  11
+
  12
+<%= link_to 'Edit'[:Edit], edit_user_path(@user) %> |
  13
+<%= link_to 'Back'[:Back], users_path %>
109  SampleApp/config/boot.rb
... ...
@@ -0,0 +1,109 @@
  1
+# Don't change this file!
  2
+# Configure your app in config/environment.rb and config/environments/*.rb
  3
+
  4
+RAILS_ROOT = "#{File.dirname(__FILE__)}/.." unless defined?(RAILS_ROOT)
  5
+
  6
+module Rails
  7
+  class << self
  8
+    def boot!
  9
+      unless booted?
  10
+        preinitialize
  11
+        pick_boot.run
  12
+      end
  13
+    end
  14
+
  15
+    def booted?
  16
+      defined? Rails::Initializer
  17
+    end
  18
+
  19
+    def pick_boot
  20
+      (vendor_rails? ? VendorBoot : GemBoot).new
  21
+    end
  22
+
  23
+    def vendor_rails?
  24
+      File.exist?("#{RAILS_ROOT}/vendor/rails")
  25
+    end
  26
+
  27
+    def preinitialize
  28
+      load(preinitializer_path) if File.exist?(preinitializer_path)
  29
+    end
  30
+
  31
+    def preinitializer_path
  32
+      "#{RAILS_ROOT}/config/preinitializer.rb"
  33
+    end
  34
+  end
  35
+
  36
+  class Boot
  37
+    def run
  38
+      load_initializer
  39
+      Rails::Initializer.run(:set_load_path)
  40
+    end
  41
+  end
  42
+
  43
+  class VendorBoot < Boot
  44
+    def load_initializer
  45
+      require "#{RAILS_ROOT}/vendor/rails/railties/lib/initializer"
  46
+      Rails::Initializer.run(:install_gem_spec_stubs)
  47
+    end
  48
+  end
  49
+
  50
+  class GemBoot < Boot
  51
+    def load_initializer
  52
+      self.class.load_rubygems
  53
+      load_rails_gem
  54
+      require 'initializer'
  55
+    end
  56
+
  57
+    def load_rails_gem
  58
+      if version = self.class.gem_version
  59
+        gem 'rails', version
  60
+      else
  61
+        gem 'rails'
  62
+      end
  63
+    rescue Gem::LoadError => load_error
  64
+      $stderr.puts %(Missing the Rails #{version} gem. Please `gem install -v=#{version} rails`, update your RAILS_GEM_VERSION setting in config/environment.rb for the Rails version you do have installed, or comment out RAILS_GEM_VERSION to use the latest version installed.)
  65
+      exit 1
  66
+    end
  67
+
  68
+    class << self
  69
+      def rubygems_version
  70
+        Gem::RubyGemsVersion if defined? Gem::RubyGemsVersion
  71
+      end
  72
+
  73
+      def gem_version
  74
+        if defined? RAILS_GEM_VERSION
  75
+          RAILS_GEM_VERSION
  76
+        elsif ENV.include?('RAILS_GEM_VERSION')
  77
+          ENV['RAILS_GEM_VERSION']
  78
+        else
  79
+          parse_gem_version(read_environment_rb)
  80
+        end
  81
+      end
  82
+
  83
+      def load_rubygems
  84
+        require 'rubygems'
  85
+
  86
+        unless rubygems_version >= '0.9.4'
  87
+          $stderr.puts %(Rails requires RubyGems >= 0.9.4 (you have #{rubygems_version}). Please `gem update --system` and try again.)
  88
+          exit 1
  89
+        end
  90
+
  91
+      rescue LoadError
  92
+        $stderr.puts %(Rails requires RubyGems >= 0.9.4. Please install RubyGems and try again: http://rubygems.rubyforge.org)
  93
+        exit 1
  94
+      end
  95
+
  96
+      def parse_gem_version(text)
  97
+        $1 if text =~ /^[^#]*RAILS_GEM_VERSION\s*=\s*["']([!~<>=]*\s*[\d.]+)["']/
  98
+      end
  99
+
  100
+      private
  101
+        def read_environment_rb
  102
+          File.read("#{RAILS_ROOT}/config/environment.rb")
  103
+        end
  104
+    end
  105
+  end
  106
+end
  107
+
  108
+# All that for this:
  109
+Rails.boot!
19  SampleApp/config/database.yml
... ...
@@ -0,0 +1,19 @@
  1
+# SQLite version 3.x
  2
+#   gem install sqlite3-ruby (not necessary on OS X Leopard)
  3
+development:
  4
+  adapter: sqlite3
  5
+  database: db/development.sqlite3
  6
+  timeout: 5000
  7
+
  8
+# Warning: The database defined as "test" will be erased and
  9
+# re-generated from your development database when you run "rake".
  10
+# Do not set this db to the same as development or production.
  11
+test:
  12
+  adapter: sqlite3
  13
+  database: db/test.sqlite3
  14
+  timeout: 5000
  15
+
  16
+production:
  17
+  adapter: sqlite3
  18
+  database: db/production.sqlite3
  19
+  timeout: 5000
67  SampleApp/config/environment.rb
... ...
@@ -0,0 +1,67 @@
  1
+# Be sure to restart your server when you modify this file
  2
+
  3
+# Uncomment below to force Rails into production mode when
  4
+# you don't control web/app server and can't set it the proper way
  5
+# ENV['RAILS_ENV'] ||= 'production'
  6
+
  7
+# Specifies gem version of Rails to use when vendor/rails is not present
  8
+RAILS_GEM_VERSION = '2.1.0' unless defined? RAILS_GEM_VERSION
  9
+
  10
+# Bootstrap the Rails environment, frameworks, and default configuration
  11
+require File.join(File.dirname(__FILE__), 'boot')
  12
+
  13
+Rails::Initializer.run do |config|
  14
+  # Settings in config/environments/* take precedence over those specified here.
  15
+  # Application configuration should go into files in config/initializers
  16
+  # -- all .rb files in that directory are automatically loaded.
  17
+  # See Rails::Configuration for more options.
  18
+
  19
+  # Skip frameworks you're not going to use. To use Rails without a database
  20
+  # you must remove the Active Record framework.
  21
+  # config.frameworks -= [ :active_record, :active_resource, :action_mailer ]
  22
+
  23
+  # Specify gems that this application depends on. 
  24
+  # They can then be installed with "rake gems:install" on new installations.
  25
+  # config.gem "bj"
  26
+  # config.gem "hpricot", :version => '0.6', :source => "http://code.whytheluckystiff.net"
  27
+  # config.gem "aws-s3", :lib => "aws/s3"
  28
+
  29
+  # Only load the plugins named here, in the order given. By default, all plugins 
  30
+  # in vendor/plugins are loaded in alphabetical order.
  31
+  # :all can be used as a placeholder for all plugins not explicitly named
  32
+  # config.plugins = [ :exception_notification, :ssl_requirement, :all ]
  33
+
  34
+  # Add additional load paths for your own custom dirs
  35
+  # config.load_paths += %W( #{RAILS_ROOT}/extras )
  36
+
  37
+  # Force all environments to use the same logger level
  38
+  # (by default production uses :info, the others :debug)
  39
+  # config.log_level = :debug
  40
+
  41
+  # Make Time.zone default to the specified zone, and make Active Record store time values
  42
+  # in the database in UTC, and return them converted to the specified local zone.
  43
+  # Run "rake -D time" for a list of tasks for finding time zone names. Uncomment to use default local time.
  44
+  config.time_zone = 'UTC'
  45
+
  46
+  # Your secret key for verifying cookie session data integrity.
  47
+  # If you change this key, all old sessions will become invalid!
  48
+  # Make sure the secret is at least 30 characters and all random, 
  49
+  # no regular words or you'll be exposed to dictionary attacks.
  50
+  config.action_controller.session = {
  51
+    :session_key => '_sample_session',
  52
+    :secret      => 'd04eb7b652bc627b96fe6dd5c02fe98ab5ebeb62990a76df18c9411a92f342d36f6ad1f969c77b756acff1b25167cf90c2cabf42958d041790bad01fd44e9558'
  53
+  }
  54
+
  55
+  # Use the database for sessions instead of the cookie-based default,
  56
+  # which shouldn't be used to store highly confidential information
  57
+  # (create the session table with "rake db:sessions:create")
  58
+  # config.action_controller.session_store = :active_record_store
  59
+
  60
+  # Use SQL instead of Active Record's schema dumper when creating the test database.
  61
+  # This is necessary if your schema can't be completely dumped by the schema dumper,
  62
+  # like if you have constraints or database-specific column types
  63
+  # config.active_record.schema_format = :sql
  64
+
  65
+  # Activate observers that should always be running
  66
+  # config.active_record.observers = :cacher, :garbage_collector
  67
+end
17  SampleApp/config/environments/development.rb
... ...
@@ -0,0 +1,17 @@
  1
+# Settings specified here will take precedence over those in config/environment.rb
  2
+
  3
+# In the development environment your application's code is reloaded on
  4
+# every request.  This slows down response time but is perfect for development
  5
+# since you don't have to restart the webserver when you make code changes.
  6
+config.cache_classes = false
  7
+
  8
+# Log error messages when you accidentally call methods on nil.
  9
+config.whiny_nils = true
  10
+
  11
+# Show full error reports and disable caching
  12
+config.action_controller.consider_all_requests_local = true
  13
+config.action_view.debug_rjs                         = true
  14
+config.action_controller.perform_caching             = false
  15
+
  16
+# Don't care if the mailer can't send
  17
+config.action_mailer.raise_delivery_errors = false
22  SampleApp/config/environments/production.rb
... ...
@@ -0,0 +1,22 @@
  1
+# Settings specified here will take precedence over those in config/environment.rb
  2
+
  3
+# The production environment is meant for finished, "live" apps.
  4
+# Code is not reloaded between requests
  5
+config.cache_classes = true
  6
+
  7
+# Use a different logger for distributed setups
  8
+# config.logger = SyslogLogger.new
  9
+
  10
+# Full error reports are disabled and caching is turned on
  11
+config.action_controller.consider_all_requests_local = false
  12
+config.action_controller.perform_caching             = true
  13
+config.action_view.cache_template_loading            = true
  14
+
  15
+# Use a different cache store in production
  16
+# config.cache_store = :mem_cache_store
  17
+
  18
+# Enable serving of images, stylesheets, and javascripts from an asset server
  19
+# config.action_controller.asset_host                  = "http://assets.example.com"
  20
+
  21
+# Disable delivery errors, bad email addresses will be ignored
  22
+# config.action_mailer.raise_delivery_errors = false
22  SampleApp/config/environments/test.rb
... ...
@@ -0,0 +1,22 @@
  1
+# Settings specified here will take precedence over those in config/environment.rb
  2
+
  3
+# The test environment is used exclusively to run your application's
  4
+# test suite.  You never need to work with it otherwise.  Remember that
  5
+# your test database is "scratch space" for the test suite and is wiped
  6
+# and recreated between test runs.  Don't rely on the data there!
  7
+config.cache_classes = true
  8
+
  9
+# Log error messages when you accidentally call methods on nil.
  10
+config.whiny_nils = true
  11
+
  12
+# Show full error reports and disable caching
  13
+config.action_controller.consider_all_requests_local = true
  14
+config.action_controller.perform_caching             = false
  15
+
  16
+# Disable request forgery protection in test environment
  17
+config.action_controller.allow_forgery_protection    = false
  18
+
  19
+# Tell Action Mailer not to deliver emails to the real world.
  20
+# The :test delivery method accumulates sent emails in the
  21
+# ActionMailer::Base.deliveries array.
  22
+config.action_mailer.delivery_method = :test
10  SampleApp/config/initializers/inflections.rb
... ...
@@ -0,0 +1,10 @@
  1
+# Be sure to restart your server when you modify this file.
  2
+
  3
+# Add new inflection rules using the following format 
  4
+# (all these examples are active by default):
  5
+# Inflector.inflections do |inflect|
  6
+#   inflect.plural /^(ox)$/i, '\1en'
  7
+#   inflect.singular /^(ox)en/i, '\1'
  8
+#   inflect.irregular 'person', 'people'
  9
+#   inflect.uncountable %w( fish sheep )
  10
+# end
5  SampleApp/config/initializers/mime_types.rb
... ...
@@ -0,0 +1,5 @@
  1
+# Be sure to restart your server when you modify this file.
  2
+
  3
+# Add new mime types for use in respond_to blocks:
  4
+# Mime::Type.register "text/richtext", :rtf
  5
+# Mime::Type.register_alias "text/html", :iphone
15  SampleApp/config/initializers/new_rails_defaults.rb
... ...
@@ -0,0 +1,15 @@
  1
+# These settings change the behavior of Rails 2 apps and will be defaults
  2
+# for Rails 3. You can remove this initializer when Rails 3 is released.
  3
+
  4
+# Include Active Record class name as root for JSON serialized output.
  5
+ActiveRecord::Base.include_root_in_json = true
  6
+
  7
+# Store the full class name (including module namespace) in STI type column.
  8
+ActiveRecord::Base.store_full_sti_class = true
  9
+
  10
+# Use ISO 8601 format for JSON serialized times and dates.
  11
+ActiveSupport.use_standard_json_time_format = true
  12
+
  13
+# Don't escape HTML entities in JSON, leave that for the #json_escape helper.
  14
+# if you're including raw json in an HTML page.
  15
+ActiveSupport.escape_html_entities_in_json = false
14  SampleApp/config/routes.rb
... ...
@@ -0,0 +1,14 @@
  1
+ActionController::Routing::Routes.draw do |map|
  2
+
  3
+  map.resources :users
  4
+
  5
+  # You can have the root of your site routed with map.root -- just remember to delete public/index.html.
  6
+  map.root :controller => 'users', :action => 'index'
  7
+
  8
+  # See how all your routes lay out with "rake routes"
  9
+
  10
+  # Install the default routes as the lowest priority.
  11
+  map.connect ':controller/:action/:id'
  12
+  map.connect ':controller/:action/:id.:format'
  13
+end
  14
+ActionController::Routing::Translator.translate_from_files
0  SampleApp/config/routes_en.yml
No changes.
4  SampleApp/config/routes_es.yml
... ...
@@ -0,0 +1,4 @@
  1
+edit: editar
  2
+new: crear
  3
+users: usuarios
  4
+show: mostrar
BIN  SampleApp/db/development.sqlite3
Binary file not shown
14  SampleApp/db/migrate/20080606095256_create_users.rb
... ...
@@ -0,0 +1,14 @@
  1
+class CreateUsers < ActiveRecord::Migration
  2
+  def self.up
  3
+    create_table :users do |t|
  4
+      t.string :name
  5
+      t.string :last_name
  6
+
  7
+      t.timestamps
  8
+    end
  9
+  end
  10
+
  11
+  def self.down
  12
+    drop_table :users
  13
+  end
  14
+end
21  SampleApp/db/schema.rb