railties 3.0.20 → 3.1.0.beta1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +36 -49
- data/README.rdoc +2 -1
- data/guides/assets/stylesheets/fixes.css +16 -0
- data/guides/rails_guides.rb +2 -2
- data/guides/rails_guides/generator.rb +8 -3
- data/guides/rails_guides/textile_extensions.rb +4 -2
- data/guides/source/2_2_release_notes.textile +3 -3
- data/guides/source/2_3_release_notes.textile +2 -2
- data/guides/source/3_0_release_notes.textile +14 -14
- data/guides/source/action_controller_overview.textile +54 -79
- data/guides/source/action_mailer_basics.textile +39 -9
- data/guides/source/action_view_overview.textile +257 -211
- data/guides/source/active_record_basics.textile +1 -1
- data/guides/source/active_record_querying.textile +217 -27
- data/guides/source/active_record_validations_callbacks.textile +94 -25
- data/guides/source/active_support_core_extensions.textile +109 -77
- data/guides/source/ajax_on_rails.textile +15 -150
- data/guides/source/api_documentation_guidelines.textile +12 -12
- data/guides/source/association_basics.textile +74 -60
- data/guides/source/caching_with_rails.textile +59 -60
- data/guides/source/command_line.textile +46 -47
- data/guides/source/configuring.textile +55 -37
- data/guides/source/contribute.textile +7 -7
- data/guides/source/contributing_to_ruby_on_rails.textile +14 -23
- data/guides/source/credits.html.erb +3 -3
- data/guides/source/debugging_rails_applications.textile +59 -46
- data/guides/source/form_helpers.textile +76 -31
- data/guides/source/generators.textile +39 -40
- data/guides/source/getting_started.textile +73 -94
- data/guides/source/i18n.textile +64 -58
- data/guides/source/index.html.erb +3 -3
- data/guides/source/initialization.textile +634 -3284
- data/guides/source/layout.html.erb +6 -7
- data/guides/source/layouts_and_rendering.textile +59 -60
- data/guides/source/migrations.textile +63 -59
- data/guides/source/nested_model_forms.textile +2 -2
- data/guides/source/performance_testing.textile +16 -16
- data/guides/source/plugins.textile +236 -1280
- data/guides/source/rails_application_templates.textile +37 -29
- data/guides/source/rails_on_rack.textile +4 -9
- data/guides/source/routing.textile +96 -75
- data/guides/source/ruby_on_rails_guides_guidelines.textile +19 -12
- data/guides/source/security.textile +57 -30
- data/guides/source/testing.textile +26 -24
- data/guides/w3c_validator.rb +2 -2
- data/lib/rails.rb +1 -7
- data/lib/rails/application.rb +46 -76
- data/lib/rails/application/bootstrap.rb +6 -11
- data/lib/rails/application/configuration.rb +43 -40
- data/lib/rails/application/finisher.rb +16 -4
- data/lib/rails/application/railties.rb +6 -24
- data/lib/rails/application/routes_reloader.rb +45 -0
- data/lib/rails/backtrace_cleaner.rb +1 -1
- data/lib/rails/cli.rb +7 -5
- data/lib/rails/commands.rb +27 -2
- data/lib/rails/commands/application.rb +14 -1
- data/lib/rails/commands/benchmarker.rb +3 -1
- data/lib/rails/commands/dbconsole.rb +2 -2
- data/lib/rails/commands/destroy.rb +3 -1
- data/lib/rails/commands/generate.rb +3 -1
- data/lib/rails/commands/plugin.rb +2 -7
- data/lib/rails/commands/plugin_new.rb +10 -0
- data/lib/rails/commands/profiler.rb +3 -1
- data/lib/rails/commands/server.rb +4 -0
- data/lib/rails/configuration.rb +8 -81
- data/lib/rails/console/app.rb +2 -2
- data/lib/rails/engine.rb +460 -78
- data/lib/rails/engine/configuration.rb +46 -49
- data/lib/rails/engine/railties.rb +33 -0
- data/lib/rails/generators.rb +11 -5
- data/lib/rails/generators/actions.rb +2 -27
- data/lib/rails/generators/app_base.rb +216 -0
- data/lib/rails/generators/base.rb +3 -2
- data/lib/rails/generators/erb/scaffold/templates/index.html.erb +1 -1
- data/lib/rails/generators/generated_attribute.rb +2 -1
- data/lib/rails/generators/migration.rb +6 -2
- data/lib/rails/generators/named_base.rb +79 -3
- data/lib/rails/generators/rails/app/app_generator.rb +44 -209
- data/lib/rails/generators/rails/app/templates/Gemfile +15 -31
- data/lib/rails/generators/rails/app/templates/README +2 -2
- data/lib/rails/generators/rails/app/templates/Rakefile +1 -1
- data/lib/rails/generators/rails/app/templates/{public → app/assets}/images/rails.png +0 -0
- data/lib/rails/generators/rails/app/templates/app/assets/javascripts/application.js.tt +8 -0
- data/lib/rails/generators/rails/app/templates/app/assets/stylesheets/application.css +5 -0
- data/lib/rails/generators/rails/app/templates/app/mailers/.empty_directory +0 -0
- data/lib/rails/generators/rails/app/templates/app/models/.empty_directory +0 -0
- data/lib/rails/generators/rails/app/templates/app/views/layouts/application.html.erb.tt +4 -4
- data/lib/rails/generators/rails/app/templates/config/application.rb +19 -3
- data/lib/rails/generators/rails/app/templates/config/databases/jdbcmysql.yml +4 -4
- data/lib/rails/generators/rails/app/templates/config/databases/jdbcpostgresql.yml +11 -6
- data/lib/rails/generators/rails/app/templates/config/databases/jdbcsqlite3.yml +3 -3
- data/lib/rails/generators/rails/app/templates/config/databases/oracle.yml +1 -1
- data/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt +1 -2
- data/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt +14 -11
- data/lib/rails/generators/rails/app/templates/config/environments/test.rb.tt +5 -1
- data/lib/rails/generators/rails/app/templates/config/initializers/session_store.rb.tt +1 -1
- data/lib/rails/generators/rails/app/templates/config/initializers/wrap_parameters.rb.tt +12 -0
- data/lib/rails/generators/rails/app/templates/config/locales/en.yml +1 -1
- data/lib/rails/generators/rails/app/templates/config/routes.rb +1 -1
- data/lib/rails/generators/rails/app/templates/db/{seeds.rb → seeds.rb.tt} +2 -2
- data/lib/rails/generators/rails/app/templates/public/index.html +10 -8
- data/lib/rails/generators/rails/app/templates/public/stylesheets/.empty_directory +0 -0
- data/lib/rails/generators/rails/app/templates/test/fixtures/.empty_directory +0 -0
- data/lib/rails/generators/rails/app/templates/test/functional/.empty_directory +0 -0
- data/lib/rails/generators/rails/app/templates/test/integration/.empty_directory +0 -0
- data/lib/rails/generators/rails/app/templates/test/{test_helper.rb.tt → test_helper.rb} +0 -0
- data/lib/rails/generators/rails/app/templates/test/unit/.empty_directory +0 -0
- data/lib/rails/generators/rails/assets/USAGE +20 -0
- data/lib/rails/generators/rails/assets/assets_generator.rb +39 -0
- data/lib/rails/generators/rails/assets/templates/javascript.js +2 -0
- data/lib/rails/generators/rails/assets/templates/javascript.js.coffee +3 -0
- data/lib/rails/generators/rails/assets/templates/stylesheet.css +4 -0
- data/lib/rails/generators/rails/assets/templates/stylesheet.css.scss +5 -0
- data/lib/rails/generators/rails/controller/controller_generator.rb +1 -1
- data/lib/rails/generators/rails/controller/templates/controller.rb +2 -0
- data/lib/rails/generators/rails/generator/generator_generator.rb +2 -2
- data/lib/rails/generators/rails/generator/templates/templates/.empty_directory +0 -0
- data/lib/rails/generators/rails/helper/templates/helper.rb +2 -0
- data/lib/rails/generators/rails/plugin/plugin_generator.rb +7 -0
- data/lib/rails/generators/rails/plugin/templates/Rakefile.tt +4 -4
- data/lib/rails/generators/rails/plugin_new/USAGE +10 -0
- data/lib/rails/generators/rails/plugin_new/plugin_new_generator.rb +303 -0
- data/lib/rails/generators/rails/plugin_new/templates/%name%.gemspec +9 -0
- data/lib/rails/generators/rails/plugin_new/templates/Gemfile +11 -0
- data/lib/rails/generators/rails/plugin_new/templates/MIT-LICENSE +20 -0
- data/lib/rails/generators/rails/plugin_new/templates/README.rdoc +3 -0
- data/lib/rails/generators/rails/plugin_new/templates/Rakefile +21 -0
- data/lib/rails/generators/rails/plugin_new/templates/app/controllers/%name%/application_controller.rb.tt +4 -0
- data/lib/rails/generators/rails/plugin_new/templates/app/helpers/%name%/application_helper.rb.tt +4 -0
- data/lib/rails/generators/rails/plugin_new/templates/app/models/.empty_directory +0 -0
- data/lib/rails/generators/rails/plugin_new/templates/config/routes.rb +6 -0
- data/lib/rails/generators/rails/plugin_new/templates/gitignore +6 -0
- data/lib/rails/generators/rails/plugin_new/templates/lib/%name%.rb +6 -0
- data/lib/rails/generators/rails/plugin_new/templates/lib/%name%/engine.rb +7 -0
- data/lib/rails/generators/rails/plugin_new/templates/lib/tasks/%name%_tasks.rake +4 -0
- data/lib/rails/generators/rails/plugin_new/templates/rails/application.rb +16 -0
- data/lib/rails/generators/rails/plugin_new/templates/rails/boot.rb +10 -0
- data/lib/rails/generators/rails/plugin_new/templates/rails/routes.rb +4 -0
- data/lib/rails/generators/rails/plugin_new/templates/script/rails.tt +5 -0
- data/lib/rails/generators/rails/plugin_new/templates/test/%name%_test.rb +7 -0
- data/lib/rails/generators/rails/plugin_new/templates/test/integration/navigation_test.rb +12 -0
- data/lib/rails/generators/rails/plugin_new/templates/test/test_helper.rb +10 -0
- data/lib/rails/generators/rails/resource/resource_generator.rb +2 -2
- data/lib/rails/generators/rails/scaffold/scaffold_generator.rb +20 -1
- data/lib/rails/generators/rails/{stylesheets → scaffold}/templates/scaffold.css +0 -0
- data/lib/rails/generators/rails/scaffold/templates/scaffold.css.scss +58 -0
- data/lib/rails/generators/rails/scaffold_controller/templates/controller.rb +21 -19
- data/lib/rails/generators/resource_helpers.rb +3 -3
- data/lib/rails/generators/test_case.rb +2 -20
- data/lib/rails/generators/test_unit/controller/templates/functional_test.rb +5 -4
- data/lib/rails/generators/test_unit/helper/templates/helper_test.rb +2 -0
- data/lib/rails/generators/test_unit/integration/templates/integration_test.rb +3 -4
- data/lib/rails/generators/test_unit/mailer/templates/functional_test.rb +5 -4
- data/lib/rails/generators/test_unit/model/templates/fixtures.yml +1 -1
- data/lib/rails/generators/test_unit/model/templates/unit_test.rb +5 -4
- data/lib/rails/generators/test_unit/observer/templates/unit_test.rb +5 -4
- data/lib/rails/generators/test_unit/plugin/templates/%file_name%_test.rb.tt +3 -4
- data/lib/rails/generators/test_unit/scaffold/templates/functional_test.rb +7 -5
- data/lib/rails/info.rb +0 -1
- data/lib/rails/paths.rb +119 -65
- data/lib/rails/plugin.rb +18 -19
- data/lib/rails/rack/log_tailer.rb +1 -1
- data/lib/rails/railtie.rb +50 -47
- data/lib/rails/railtie/configurable.rb +20 -10
- data/lib/rails/railtie/configuration.rb +20 -19
- data/lib/rails/source_annotation_extractor.rb +5 -5
- data/lib/rails/tasks.rb +1 -0
- data/lib/rails/tasks/assets.rake +10 -0
- data/lib/rails/tasks/documentation.rake +2 -8
- data/lib/rails/tasks/engine.rake +69 -0
- data/lib/rails/tasks/framework.rake +4 -21
- data/lib/rails/tasks/misc.rake +1 -1
- data/lib/rails/tasks/routes.rake +2 -1
- data/lib/rails/test_help.rb +17 -1
- data/lib/rails/test_unit/railtie.rb +1 -1
- data/lib/rails/test_unit/testing.rake +8 -3
- data/lib/rails/version.rb +3 -3
- metadata +128 -100
- checksums.yaml +0 -7
- data/lib/rails/application/configurable.rb +0 -19
- data/lib/rails/console/sandbox.rb +0 -6
- data/lib/rails/deprecation.rb +0 -41
- data/lib/rails/engine/configurable.rb +0 -25
- data/lib/rails/generators/rails/app/templates/config/databases/jdbc.yml +0 -62
- data/lib/rails/generators/rails/app/templates/public/javascripts/application.js +0 -2
- data/lib/rails/generators/rails/app/templates/public/javascripts/controls.js +0 -965
- data/lib/rails/generators/rails/app/templates/public/javascripts/dragdrop.js +0 -974
- data/lib/rails/generators/rails/app/templates/public/javascripts/effects.js +0 -1123
- data/lib/rails/generators/rails/app/templates/public/javascripts/prototype.js +0 -6001
- data/lib/rails/generators/rails/app/templates/public/javascripts/rails.js +0 -202
- data/lib/rails/generators/rails/stylesheets/USAGE +0 -5
- data/lib/rails/generators/rails/stylesheets/stylesheets_generator.rb +0 -9
- data/lib/rails/info_routes.rb +0 -3
@@ -11,19 +11,19 @@ endprologue.
|
|
11
11
|
|
12
12
|
h3. Usage
|
13
13
|
|
14
|
-
To apply a template, you need to provide the Rails generator with the location of the template you wish to apply, using -m option
|
14
|
+
To apply a template, you need to provide the Rails generator with the location of the template you wish to apply, using -m option:
|
15
15
|
|
16
16
|
<shell>
|
17
17
|
$ rails new blog -m ~/template.rb
|
18
18
|
</shell>
|
19
19
|
|
20
|
-
It's also possible to apply a template using a URL
|
20
|
+
It's also possible to apply a template using a URL:
|
21
21
|
|
22
22
|
<shell>
|
23
|
-
$ rails new blog -m
|
23
|
+
$ rails new blog -m https://gist.github.com/755496.txt
|
24
24
|
</shell>
|
25
25
|
|
26
|
-
Alternatively, you can use the rake task +rails:template+ to apply a template to an existing Rails application
|
26
|
+
Alternatively, you can use the rake task +rails:template+ to apply a template to an existing Rails application:
|
27
27
|
|
28
28
|
<shell>
|
29
29
|
$ rake rails:template LOCATION=~/template.rb
|
@@ -31,13 +31,13 @@ $ rake rails:template LOCATION=~/template.rb
|
|
31
31
|
|
32
32
|
h3. Template API
|
33
33
|
|
34
|
-
Rails templates API is very self explanatory and easy to understand. Here's an example of a typical Rails template
|
34
|
+
Rails templates API is very self explanatory and easy to understand. Here's an example of a typical Rails template:
|
35
35
|
|
36
36
|
<ruby>
|
37
37
|
# template.rb
|
38
38
|
run "rm public/index.html"
|
39
39
|
generate(:scaffold, "person name:string")
|
40
|
-
route "
|
40
|
+
route "root :to => 'people#index'"
|
41
41
|
rake("db:migrate")
|
42
42
|
|
43
43
|
git :init
|
@@ -45,20 +45,20 @@ git :add => "."
|
|
45
45
|
git :commit => "-a -m 'Initial commit'"
|
46
46
|
</ruby>
|
47
47
|
|
48
|
-
The following sections outlines the primary methods provided by the API
|
48
|
+
The following sections outlines the primary methods provided by the API:
|
49
49
|
|
50
50
|
h4. gem(name, options = {})
|
51
51
|
|
52
|
-
Adds a +
|
52
|
+
Adds a +gem+ entry for the supplied gem to the generated application’s +Gemfile+.
|
53
53
|
|
54
|
-
For example, if your application depends on the gems +bj+ and +nokogiri
|
54
|
+
For example, if your application depends on the gems +bj+ and +nokogiri+:
|
55
55
|
|
56
56
|
<ruby>
|
57
57
|
gem "bj"
|
58
58
|
gem "nokogiri"
|
59
59
|
</ruby>
|
60
60
|
|
61
|
-
Please note that this will NOT install the gems for you. So you may want to run the +rake gems:install+ task too
|
61
|
+
Please note that this will NOT install the gems for you. So you may want to run the +rake gems:install+ task too:
|
62
62
|
|
63
63
|
<ruby>
|
64
64
|
rake "gems:install"
|
@@ -66,17 +66,27 @@ rake "gems:install"
|
|
66
66
|
|
67
67
|
And let Rails take care of installing the required gems if they’re not already installed.
|
68
68
|
|
69
|
+
h4. add_source(source, options = {})
|
70
|
+
|
71
|
+
Adds the given source to the generated application's +Gemfile+.
|
72
|
+
|
73
|
+
For example, if you need to source a gem from "http://code.whytheluckystiff.net":
|
74
|
+
|
75
|
+
<ruby>
|
76
|
+
add_source "http://code.whytheluckystiff.net"
|
77
|
+
</ruby>
|
78
|
+
|
69
79
|
h4. plugin(name, options = {})
|
70
80
|
|
71
81
|
Installs a plugin to the generated application.
|
72
82
|
|
73
|
-
Plugin can be installed from Git
|
83
|
+
Plugin can be installed from Git:
|
74
84
|
|
75
85
|
<ruby>
|
76
86
|
plugin 'authentication', :git => 'git://github.com/foor/bar.git'
|
77
87
|
</ruby>
|
78
88
|
|
79
|
-
You can even install plugins as git submodules
|
89
|
+
You can even install plugins as git submodules:
|
80
90
|
|
81
91
|
<ruby>
|
82
92
|
plugin 'authentication', :git => 'git://github.com/foor/bar.git',
|
@@ -85,7 +95,7 @@ plugin 'authentication', :git => 'git://github.com/foor/bar.git',
|
|
85
95
|
|
86
96
|
Please note that you need to +git :init+ before you can install a plugin as a submodule.
|
87
97
|
|
88
|
-
Or use plain old SVN
|
98
|
+
Or use plain old SVN:
|
89
99
|
|
90
100
|
<ruby>
|
91
101
|
plugin 'usingsvn', :svn => 'svn://example.com/usingsvn/trunk'
|
@@ -95,7 +105,7 @@ h4. vendor/lib/file/initializer(filename, data = nil, &block)
|
|
95
105
|
|
96
106
|
Adds an initializer to the generated application’s +config/initializers+ directory.
|
97
107
|
|
98
|
-
Lets say you like using +Object#not_nil?+ and +Object#not_blank
|
108
|
+
Lets say you like using +Object#not_nil?+ and +Object#not_blank?+:
|
99
109
|
|
100
110
|
<ruby>
|
101
111
|
initializer 'bloatlol.rb', <<-CODE
|
@@ -113,7 +123,7 @@ CODE
|
|
113
123
|
|
114
124
|
Similarly +lib()+ creates a file in the +lib/+ directory and +vendor()+ creates a file in the +vendor/+ directory.
|
115
125
|
|
116
|
-
There is even +file()+, which accepts a relative path from +Rails.root+ and creates all the directories/file needed
|
126
|
+
There is even +file()+, which accepts a relative path from +Rails.root+ and creates all the directories/file needed:
|
117
127
|
|
118
128
|
<ruby>
|
119
129
|
file 'app/components/foo.rb', <<-CODE
|
@@ -126,7 +136,7 @@ That’ll create +app/components+ directory and put +foo.rb+ in there.
|
|
126
136
|
|
127
137
|
h4. rakefile(filename, data = nil, &block)
|
128
138
|
|
129
|
-
Creates a new rake file under +lib/tasks+ with the supplied tasks
|
139
|
+
Creates a new rake file under +lib/tasks+ with the supplied tasks:
|
130
140
|
|
131
141
|
<ruby>
|
132
142
|
rakefile("bootstrap.rake") do
|
@@ -144,7 +154,7 @@ The above creates +lib/tasks/bootstrap.rake+ with a +boot:strap+ rake task.
|
|
144
154
|
|
145
155
|
h4. generate(what, args)
|
146
156
|
|
147
|
-
Runs the supplied rails generator with given arguments. For example, I love to scaffold some whenever I’m playing with Rails
|
157
|
+
Runs the supplied rails generator with given arguments. For example, I love to scaffold some whenever I’m playing with Rails:
|
148
158
|
|
149
159
|
<ruby>
|
150
160
|
generate(:scaffold, "person", "name:string", "address:text", "age:number")
|
@@ -152,7 +162,7 @@ generate(:scaffold, "person", "name:string", "address:text", "age:number")
|
|
152
162
|
|
153
163
|
h4. run(command)
|
154
164
|
|
155
|
-
Executes an arbitrary command. Just like the backticks. Let's say you want to remove the +public/index.html+ file
|
165
|
+
Executes an arbitrary command. Just like the backticks. Let's say you want to remove the +public/index.html+ file:
|
156
166
|
|
157
167
|
<ruby>
|
158
168
|
run "rm public/index.html"
|
@@ -160,19 +170,19 @@ run "rm public/index.html"
|
|
160
170
|
|
161
171
|
h4. rake(command, options = {})
|
162
172
|
|
163
|
-
Runs the supplied rake tasks in the Rails application. Let's say you want to migrate the database
|
173
|
+
Runs the supplied rake tasks in the Rails application. Let's say you want to migrate the database:
|
164
174
|
|
165
175
|
<ruby>
|
166
176
|
rake "db:migrate"
|
167
177
|
</ruby>
|
168
178
|
|
169
|
-
You can also run rake tasks with a different Rails environment
|
179
|
+
You can also run rake tasks with a different Rails environment:
|
170
180
|
|
171
181
|
<ruby>
|
172
182
|
rake "db:migrate", :env => 'production'
|
173
183
|
</ruby>
|
174
184
|
|
175
|
-
Or even use sudo
|
185
|
+
Or even use sudo:
|
176
186
|
|
177
187
|
<ruby>
|
178
188
|
rake "gems:install", :sudo => true
|
@@ -180,15 +190,15 @@ rake "gems:install", :sudo => true
|
|
180
190
|
|
181
191
|
h4. route(routing_code)
|
182
192
|
|
183
|
-
This adds a routing entry to the +config/routes.rb+ file. In above steps, we generated a person scaffold and also removed +public/index.html+. Now to make +PeopleController#index+ as the default page for the application
|
193
|
+
This adds a routing entry to the +config/routes.rb+ file. In above steps, we generated a person scaffold and also removed +public/index.html+. Now to make +PeopleController#index+ as the default page for the application:
|
184
194
|
|
185
195
|
<ruby>
|
186
|
-
route "
|
196
|
+
route "root :to => 'person#index'"
|
187
197
|
</ruby>
|
188
198
|
|
189
199
|
h4. inside(dir)
|
190
200
|
|
191
|
-
|
201
|
+
Enables you to run a command from the given directory. For example, if you have a copy of edge rails that you wish to symlink from your new apps, you can do this:
|
192
202
|
|
193
203
|
<ruby>
|
194
204
|
inside('vendor') do
|
@@ -196,11 +206,9 @@ inside('vendor') do
|
|
196
206
|
end
|
197
207
|
</ruby>
|
198
208
|
|
199
|
-
So +inside()+ runs the command from the given directory.
|
200
|
-
|
201
209
|
h4. ask(question)
|
202
210
|
|
203
|
-
+ask()+ gives you a chance to get some feedback from the user and use it in your templates. Lets say you want your user to name the new shiny library you’re adding
|
211
|
+
+ask()+ gives you a chance to get some feedback from the user and use it in your templates. Lets say you want your user to name the new shiny library you’re adding:
|
204
212
|
|
205
213
|
<ruby>
|
206
214
|
lib_name = ask("What do you want to call the shiny library ?")
|
@@ -214,7 +222,7 @@ CODE
|
|
214
222
|
|
215
223
|
h4. yes?(question) or no?(question)
|
216
224
|
|
217
|
-
These methods let you ask questions from templates and decide the flow based on the user’s answer. Lets say you want to freeze rails only if the user want to
|
225
|
+
These methods let you ask questions from templates and decide the flow based on the user’s answer. Lets say you want to freeze rails only if the user want to:
|
218
226
|
|
219
227
|
<ruby>
|
220
228
|
rake("rails:freeze:gems") if yes?("Freeze rails gems ?")
|
@@ -223,7 +231,7 @@ no?(question) acts just the opposite.
|
|
223
231
|
|
224
232
|
h4. git(:must => "-a love")
|
225
233
|
|
226
|
-
Rails templates let you run any git command
|
234
|
+
Rails templates let you run any git command:
|
227
235
|
|
228
236
|
<ruby>
|
229
237
|
git :init
|
@@ -17,12 +17,7 @@ bq. Rack provides a minimal, modular and adaptable interface for developing web
|
|
17
17
|
|
18
18
|
- "Rack API Documentation":http://rack.rubyforge.org/doc/
|
19
19
|
|
20
|
-
Explaining Rack is not really in the scope of this guide. In case you are not familiar with Rack's basics, you should check out the
|
21
|
-
|
22
|
-
* "Official Rack Website":http://rack.github.com
|
23
|
-
* "Introducing Rack":http://chneukirchen.org/blog/archive/2007/02/introducing-rack.html
|
24
|
-
* "Ruby on Rack #1 - Hello Rack!":http://m.onkey.org/2008/11/17/ruby-on-rack-1
|
25
|
-
* "Ruby on Rack #2 - The Builder":http://m.onkey.org/2008/11/18/ruby-on-rack-2-rack-builder
|
20
|
+
Explaining Rack is not really in the scope of this guide. In case you are not familiar with Rack's basics, you should check out the "Resources":#resources section below.
|
26
21
|
|
27
22
|
h3. Rails on Rack
|
28
23
|
|
@@ -68,13 +63,13 @@ run ActionController::Dispatcher.new
|
|
68
63
|
And start the server:
|
69
64
|
|
70
65
|
<shell>
|
71
|
-
|
66
|
+
$ rackup config.ru
|
72
67
|
</shell>
|
73
68
|
|
74
69
|
To find out more about different +rackup+ options:
|
75
70
|
|
76
71
|
<shell>
|
77
|
-
|
72
|
+
$ rackup --help
|
78
73
|
</shell>
|
79
74
|
|
80
75
|
h3. Action Controller Middleware Stack
|
@@ -165,7 +160,7 @@ Much of Action Controller's functionality is implemented as Middlewares. The fol
|
|
165
160
|
|_.Middleware|_.Purpose|
|
166
161
|
|+Rack::Lock+|Sets +env["rack.multithread"]+ flag to +true+ and wraps the application within a Mutex.|
|
167
162
|
|+ActionController::Failsafe+|Returns HTTP Status +500+ to the client if an exception gets raised while dispatching.|
|
168
|
-
|+ActiveRecord::QueryCache+|
|
163
|
+
|+ActiveRecord::QueryCache+|Enables the Active Record query cache.|
|
169
164
|
|+ActionController::Session::CookieStore+|Uses the cookie based session store.|
|
170
165
|
|+ActionController::Session::MemCacheStore+|Uses the memcached based session store.|
|
171
166
|
|+ActiveRecord::SessionStore+|Uses the database based session store.|
|
@@ -76,14 +76,17 @@ resources :photos
|
|
76
76
|
|
77
77
|
creates seven different routes in your application, all mapping to the +Photos+ controller:
|
78
78
|
|
79
|
-
|_. Verb |_.Path |_.action |_.used for|
|
80
|
-
|GET
|
81
|
-
|GET
|
82
|
-
|POST
|
83
|
-
|GET
|
84
|
-
|GET
|
85
|
-
|PUT
|
86
|
-
|DELETE
|
79
|
+
|_. HTTP Verb |_.Path |_.action |_.used for |
|
80
|
+
|GET |/photos |index |display a list of all photos |
|
81
|
+
|GET |/photos/new |new |return an HTML form for creating a new photo |
|
82
|
+
|POST |/photos |create |create a new photo |
|
83
|
+
|GET |/photos/:id |show |display a specific photo |
|
84
|
+
|GET |/photos/:id/edit |edit |return an HTML form for editing a photo |
|
85
|
+
|PUT |/photos/:id |update |update a specific photo |
|
86
|
+
|DELETE |/photos/:id |destroy |delete a specific photo |
|
87
|
+
|
88
|
+
|
89
|
+
NOTE: Rails routes are matched in the order they are specified, so if you have a +resources :photos+ above a +get 'photos/poll'+ the +show+ action's route for the +resources+ line will be matched before the +get+ line. To fix this, move the +get+ line *above* the +resources+ line so that it is matched first.
|
87
90
|
|
88
91
|
h4. Paths and URLs
|
89
92
|
|
@@ -130,13 +133,13 @@ resource :geocoder
|
|
130
133
|
|
131
134
|
creates six different routes in your application, all mapping to the +Geocoders+ controller:
|
132
135
|
|
133
|
-
|_. Verb
|
134
|
-
|GET
|
135
|
-
|POST
|
136
|
-
|GET
|
137
|
-
|GET
|
138
|
-
|PUT
|
139
|
-
|DELETE
|
136
|
+
|_.HTTP Verb |_.Path |_.action |_.used for |
|
137
|
+
|GET |/geocoder/new |new |return an HTML form for creating the geocoder |
|
138
|
+
|POST |/geocoder |create |create the new geocoder |
|
139
|
+
|GET |/geocoder |show |display the one and only geocoder resource |
|
140
|
+
|GET |/geocoder/edit |edit |return an HTML form for editing the geocoder |
|
141
|
+
|PUT |/geocoder |update |update the one and only geocoder resource |
|
142
|
+
|DELETE |/geocoder |destroy |delete the geocoder resource |
|
140
143
|
|
141
144
|
NOTE: Because you might want to use the same controller for a singular route (+/account+) and a plural route (+/accounts/45+), singular resources map to plural controllers.
|
142
145
|
|
@@ -153,21 +156,21 @@ h4. Controller Namespaces and Routing
|
|
153
156
|
You may wish to organize groups of controllers under a namespace. Most commonly, you might group a number of administrative controllers under an +Admin::+ namespace. You would place these controllers under the +app/controllers/admin+ directory, and you can group them together in your router:
|
154
157
|
|
155
158
|
<ruby>
|
156
|
-
namespace
|
159
|
+
namespace :admin do
|
157
160
|
resources :posts, :comments
|
158
161
|
end
|
159
162
|
</ruby>
|
160
163
|
|
161
164
|
This will create a number of routes for each of the +posts+ and +comments+ controller. For +Admin::PostsController+, Rails will create:
|
162
165
|
|
163
|
-
|_. Verb |_.Path
|
164
|
-
|GET
|
165
|
-
|GET
|
166
|
-
|POST
|
167
|
-
|GET
|
168
|
-
|GET
|
169
|
-
|PUT
|
170
|
-
|DELETE
|
166
|
+
|_.HTTP Verb |_.Path |_.action |_.named helper |
|
167
|
+
|GET |/admin/posts |index | admin_posts_path |
|
168
|
+
|GET |/admin/posts/new |new | new_admin_posts_path |
|
169
|
+
|POST |/admin/posts |create | admin_posts_path |
|
170
|
+
|GET |/admin/posts/1 |show | admin_post_path(id) |
|
171
|
+
|GET |/admin/posts/1/edit |edit | edit_admin_post_path(id) |
|
172
|
+
|PUT |/admin/posts/1 |update | admin_post_path(id) |
|
173
|
+
|DELETE |/admin/posts/1 |destroy | admin_post_path(id) |
|
171
174
|
|
172
175
|
If you want to route +/posts+ (without the prefix +/admin+) to +Admin::PostsController+, you could use
|
173
176
|
|
@@ -199,14 +202,14 @@ resources :posts, :path => "/admin/posts"
|
|
199
202
|
|
200
203
|
In each of these cases, the named routes remain the same as if you did not use +scope+. In the last case, the following paths map to +PostsController+:
|
201
204
|
|
202
|
-
|_. Verb |_.Path |_.action |_. helper
|
203
|
-
|GET
|
204
|
-
|GET
|
205
|
-
|POST
|
206
|
-
|GET
|
207
|
-
|GET
|
208
|
-
|PUT
|
209
|
-
|DELETE
|
205
|
+
|_.HTTP Verb |_.Path |_.action |_.named helper |
|
206
|
+
|GET |/admin/posts |index | posts_path |
|
207
|
+
|GET |/admin/posts/new |new | posts_path |
|
208
|
+
|POST |/admin/posts |create | posts_path |
|
209
|
+
|GET |/admin/posts/1 |show | post_path(id) |
|
210
|
+
|GET |/admin/posts/1/edit |edit | edit_post_path(id) |
|
211
|
+
|PUT |/admin/posts/1 |update | post_path(id) |
|
212
|
+
|DELETE |/admin/posts/1 |destroy | post_path(id) |
|
210
213
|
|
211
214
|
h4. Nested Resources
|
212
215
|
|
@@ -232,14 +235,14 @@ end
|
|
232
235
|
|
233
236
|
In addition to the routes for magazines, this declaration will also route ads to an +AdsController+. The ad URLs require a magazine:
|
234
237
|
|
235
|
-
|_.Verb |_.Path
|
236
|
-
|GET
|
237
|
-
|GET
|
238
|
-
|POST
|
239
|
-
|GET
|
240
|
-
|GET
|
241
|
-
|PUT
|
242
|
-
|DELETE
|
238
|
+
|_.HTTP Verb |_.Path |_.action |_.used for |
|
239
|
+
|GET |/magazines/1/ads |index |display a list of all ads for a specific magazine |
|
240
|
+
|GET |/magazines/1/ads/new |new |return an HTML form for creating a new ad belonging to a specific magazine |
|
241
|
+
|POST |/magazines/1/ads |create |create a new ad belonging to a specific magazine |
|
242
|
+
|GET |/magazines/1/ads/1 |show |display a specific ad belonging to a specific magazine |
|
243
|
+
|GET |/magazines/1/ads/1/edit |edit |return an HTML form for editing an ad belonging to a specific magazine |
|
244
|
+
|PUT |/magazines/1/ads/1 |update |update a specific ad belonging to a specific magazine |
|
245
|
+
|DELETE |/magazines/1/ads/1 |destroy |delete a specific ad belonging to a specific magazine |
|
243
246
|
|
244
247
|
|
245
248
|
This will also create routing helpers such as +magazine_ads_url+ and +edit_magazine_ad_path+. These helpers take an instance of Magazine as the first parameter (+magazine_ads_url(@magazine)+).
|
@@ -318,7 +321,7 @@ resources :photos do
|
|
318
321
|
end
|
319
322
|
</ruby>
|
320
323
|
|
321
|
-
This will recognize +/photos/1/preview+ with GET, and route to the +preview+ action of
|
324
|
+
This will recognize +/photos/1/preview+ with GET, and route to the +preview+ action of +PhotosController+. It will also create the +preview_photo_url+ and +preview_photo_path+ helpers.
|
322
325
|
|
323
326
|
Within the block of member routes, each route name specifies the HTTP verb that it will recognize. You can use +get+, +put+, +post+, or +delete+ here. If you don't have multiple +member+ routes, you can also pass +:on+ to a route, eliminating the block:
|
324
327
|
|
@@ -388,7 +391,7 @@ NOTE: You can't use +namespace+ or +:module+ with a +:controller+ path segment.
|
|
388
391
|
match ':controller(/:action(/:id))', :controller => /admin\/[^\/]+/
|
389
392
|
</ruby>
|
390
393
|
|
391
|
-
TIP: By default dynamic segments don't accept dots - this is because the dot is used as a separator for formatted routes. If you need to use a dot within a dynamic segment add a constraint which overrides this - for example +:id => /[^\/]
|
394
|
+
TIP: By default dynamic segments don't accept dots - this is because the dot is used as a separator for formatted routes. If you need to use a dot within a dynamic segment add a constraint which overrides this - for example +:id+ => /[^\/]+/ allows anything except a slash.
|
392
395
|
|
393
396
|
h4. Static Segments
|
394
397
|
|
@@ -418,7 +421,7 @@ You do not need to explicitly use the +:controller+ and +:action+ symbols within
|
|
418
421
|
match 'photos/:id' => 'photos#show'
|
419
422
|
</ruby>
|
420
423
|
|
421
|
-
With this route, Rails will match an incoming path of +/photos/12+ to the +show+ action of
|
424
|
+
With this route, Rails will match an incoming path of +/photos/12+ to the +show+ action of +PhotosController+.
|
422
425
|
|
423
426
|
You can also define other defaults in a route by supplying a hash for the +:defaults+ option. This even applies to parameters that you do not specify as dynamic segments. For example:
|
424
427
|
|
@@ -497,10 +500,10 @@ You specify a request-based constraint the same way that you specify a segment c
|
|
497
500
|
match "photos", :constraints => {:subdomain => "admin"}
|
498
501
|
</ruby>
|
499
502
|
|
500
|
-
You can also specify
|
503
|
+
You can also specify constraints in a block form:
|
501
504
|
|
502
505
|
<ruby>
|
503
|
-
namespace
|
506
|
+
namespace :admin do
|
504
507
|
constraints :subdomain => "admin" do
|
505
508
|
resources :photos
|
506
509
|
end
|
@@ -554,10 +557,16 @@ match '*a/foo/*b' => 'test#index'
|
|
554
557
|
|
555
558
|
would match +zoo/woo/foo/bar/baz+ with +params[:a]+ equals +"zoo/woo"+, and +params[:b]+ equals +"bar/baz"+.
|
556
559
|
|
557
|
-
NOTE:
|
560
|
+
NOTE: Starting from Rails 3.1, wildcard routes will always match the optional format segment by default. For example if you have this route:
|
558
561
|
|
559
562
|
<ruby>
|
560
|
-
|
563
|
+
map '*pages' => 'pages#show'
|
564
|
+
</ruby>
|
565
|
+
|
566
|
+
NOTE: By requesting +"/foo/bar.json"+, your +params[:pages]+ will be equals to +"foo/bar"+ with the request format of JSON. If you want the old 3.0.x behavior back, you could supply +:format => false+ like this:
|
567
|
+
|
568
|
+
<ruby>
|
569
|
+
map '*pages' => 'pages#show', :format => false
|
561
570
|
</ruby>
|
562
571
|
|
563
572
|
h4. Redirection
|
@@ -603,7 +612,7 @@ You can specify what Rails should route +"/"+ to with the +root+ method:
|
|
603
612
|
root :to => 'pages#main'
|
604
613
|
</ruby>
|
605
614
|
|
606
|
-
You should put the +root+ route at the end of the file. You also need to delete the public/index.html
|
615
|
+
You should put the +root+ route at the end of the file. You also need to delete the +public/index.html+ file for the root route to take effect.
|
607
616
|
|
608
617
|
h3. Customizing Resourceful Routes
|
609
618
|
|
@@ -619,14 +628,14 @@ resources :photos, :controller => "images"
|
|
619
628
|
|
620
629
|
will recognize incoming paths beginning with +/photos+ but route to the +Images+ controller:
|
621
630
|
|
622
|
-
|_. Verb |_.Path |_.action |
|
623
|
-
|GET
|
624
|
-
|GET
|
625
|
-
|POST
|
626
|
-
|GET
|
627
|
-
|GET
|
628
|
-
|PUT
|
629
|
-
|DELETE
|
631
|
+
|_.HTTP Verb |_.Path |_.action |_.named helper |
|
632
|
+
|GET |/photos |index | photos_path |
|
633
|
+
|GET |/photos/new |new | new_photo_path |
|
634
|
+
|POST |/photos |create | photos_path |
|
635
|
+
|GET |/photos/1 |show | photo_path(id) |
|
636
|
+
|GET |/photos/1/edit |edit | edit_photo_path(id) |
|
637
|
+
|PUT |/photos/1 |update | photo_path(id) |
|
638
|
+
|DELETE |/photos/1 |destroy | photo_path(id) |
|
630
639
|
|
631
640
|
NOTE: Use +photos_path+, +new_photos_path+, etc. to generate paths for this resource.
|
632
641
|
|
@@ -638,7 +647,7 @@ You can use the +:constraints+ option to specify a required format on the implic
|
|
638
647
|
resources :photos, :constraints => {:id => /[A-Z][A-Z][0-9]+/}
|
639
648
|
</ruby>
|
640
649
|
|
641
|
-
This declaration
|
650
|
+
This declaration constraints the +:id+ parameter to match the supplied regular expression. So, in this case, the router would no longer match +/photos/1+ to this route. Instead, +/photos/RR27+ would match.
|
642
651
|
|
643
652
|
You can specify a single constraint to apply to a number of routes by using the block form:
|
644
653
|
|
@@ -651,7 +660,7 @@ end
|
|
651
660
|
|
652
661
|
NOTE: Of course, you can use the more advanced constraints available in non-resourceful routes in this context.
|
653
662
|
|
654
|
-
TIP: By default the +:id+ parameter doesn't accept dots - this is because the dot is used as a separator for formatted routes. If you need to use a dot within an +:id+ add a constraint which overrides this - for example +:id => /[^\/]
|
663
|
+
TIP: By default the +:id+ parameter doesn't accept dots - this is because the dot is used as a separator for formatted routes. If you need to use a dot within an +:id+ add a constraint which overrides this - for example +:id+ => /[^\/]+/ allows anything except a slash.
|
655
664
|
|
656
665
|
h4. Overriding the Named Helpers
|
657
666
|
|
@@ -663,14 +672,14 @@ resources :photos, :as => "images"
|
|
663
672
|
|
664
673
|
will recognize incoming paths beginning with +/photos+ and route the requests to +PhotosController+, but use the value of the :as option to name the helpers.
|
665
674
|
|
666
|
-
|_.HTTP verb|_.Path |_.action |_.named helper
|
667
|
-
|GET |/photos |index | images_path
|
668
|
-
|GET |/photos/new |new | new_image_path
|
669
|
-
|POST |/photos |create | images_path
|
670
|
-
|GET |/photos/1 |show | image_path |
|
671
|
-
|GET |/photos/1/edit |edit | edit_image_path |
|
672
|
-
|PUT |/photos/1 |update | image_path |
|
673
|
-
|DELETE |/photos/1 |destroy | image_path |
|
675
|
+
|_.HTTP verb|_.Path |_.action |_.named helper |
|
676
|
+
|GET |/photos |index | images_path |
|
677
|
+
|GET |/photos/new |new | new_image_path |
|
678
|
+
|POST |/photos |create | images_path |
|
679
|
+
|GET |/photos/1 |show | image_path(id) |
|
680
|
+
|GET |/photos/1/edit |edit | edit_image_path(id) |
|
681
|
+
|PUT |/photos/1 |update | image_path(id) |
|
682
|
+
|DELETE |/photos/1 |destroy | image_path(id) |
|
674
683
|
|
675
684
|
h4. Overriding the +new+ and +edit+ Segments
|
676
685
|
|
@@ -711,7 +720,7 @@ resources :photos
|
|
711
720
|
|
712
721
|
This will provide route helpers such as +admin_photos_path+, +new_admin_photo_path+ etc.
|
713
722
|
|
714
|
-
To prefix a group of
|
723
|
+
To prefix a group of route helpers, use +:as+ with +scope+:
|
715
724
|
|
716
725
|
<ruby>
|
717
726
|
scope "admin", :as => "admin" do
|
@@ -721,8 +730,20 @@ end
|
|
721
730
|
resources :photos, :accounts
|
722
731
|
</ruby>
|
723
732
|
|
733
|
+
This will generate routes such as +admin_photos_path+ and +admin_accounts_path+ which map to +/admin/photos+ and +/admin/accounts+ respectively.
|
734
|
+
|
724
735
|
NOTE: The +namespace+ scope will automatically add +:as+ as well as +:module+ and +:path+ prefixes.
|
725
736
|
|
737
|
+
You can prefix routes with a named parameter also:
|
738
|
+
|
739
|
+
<ruby>
|
740
|
+
scope ":username" do
|
741
|
+
resources :posts
|
742
|
+
end
|
743
|
+
</ruby>
|
744
|
+
|
745
|
+
This will provide you with URLs such as +/bob/posts/1+ and will allow you to reference the +username+ part of the path as +params[:username]+ in controllers, helpers and views.
|
746
|
+
|
726
747
|
h4. Restricting the Routes Created
|
727
748
|
|
728
749
|
By default, Rails creates routes for the seven default actions (index, show, new, create, edit, update, and destroy) for every RESTful route in your application. You can use the +:only+ and +:except+ options to fine-tune this behavior. The +:only+ option tells Rails to create only the specified routes:
|
@@ -755,14 +776,14 @@ end
|
|
755
776
|
|
756
777
|
Rails now creates routes to the +CategoriesController+.
|
757
778
|
|
758
|
-
|_.HTTP verb|_.Path
|
759
|
-
|GET |/kategorien
|
760
|
-
|GET |/kategorien/neu
|
761
|
-
|POST |/kategorien
|
762
|
-
|GET |/kategorien/1
|
763
|
-
|GET |/kategorien
|
764
|
-
|PUT |/kategorien/1
|
765
|
-
|DELETE |/kategorien/1
|
779
|
+
|_.HTTP verb|_.Path |_.action |_.named helper |
|
780
|
+
|GET |/kategorien |index | categories_path |
|
781
|
+
|GET |/kategorien/neu |new | new_category_path |
|
782
|
+
|POST |/kategorien |create | categories_path |
|
783
|
+
|GET |/kategorien/1 |show | category_path(id) |
|
784
|
+
|GET |/kategorien/1/bearbeiten |edit | edit_category_path(id) |
|
785
|
+
|PUT |/kategorien/1 |update | category_path(id) |
|
786
|
+
|DELETE |/kategorien/1 |destroy | category_path(id) |
|
766
787
|
|
767
788
|
h4. Overriding the Singular Form
|
768
789
|
|