mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Merge pull request #12706 from RobZolkos/master
show javascripts can be disabled in scaffold generator
This commit is contained in:
commit
6e5d409f65
1 changed files with 6 additions and 2 deletions
|
@ -207,7 +207,7 @@ $ rails generate scaffold User name:string
|
||||||
|
|
||||||
Looking at this output, it's easy to understand how generators work in Rails 3.0 and above. The scaffold generator doesn't actually generate anything, it just invokes others to do the work. This allows us to add/replace/remove any of those invocations. For instance, the scaffold generator invokes the scaffold_controller generator, which invokes erb, test_unit and helper generators. Since each generator has a single responsibility, they are easy to reuse, avoiding code duplication.
|
Looking at this output, it's easy to understand how generators work in Rails 3.0 and above. The scaffold generator doesn't actually generate anything, it just invokes others to do the work. This allows us to add/replace/remove any of those invocations. For instance, the scaffold generator invokes the scaffold_controller generator, which invokes erb, test_unit and helper generators. Since each generator has a single responsibility, they are easy to reuse, avoiding code duplication.
|
||||||
|
|
||||||
Our first customization on the workflow will be to stop generating stylesheets and test fixtures for scaffolds. We can achieve that by changing our configuration to the following:
|
Our first customization on the workflow will be to stop generating stylesheets, javascripts and test fixtures for scaffolds. We can achieve that by changing our configuration to the following:
|
||||||
|
|
||||||
```ruby
|
```ruby
|
||||||
config.generators do |g|
|
config.generators do |g|
|
||||||
|
@ -215,10 +215,11 @@ config.generators do |g|
|
||||||
g.template_engine :erb
|
g.template_engine :erb
|
||||||
g.test_framework :test_unit, fixture: false
|
g.test_framework :test_unit, fixture: false
|
||||||
g.stylesheets false
|
g.stylesheets false
|
||||||
|
g.javascripts false
|
||||||
end
|
end
|
||||||
```
|
```
|
||||||
|
|
||||||
If we generate another resource with the scaffold generator, we can see that neither stylesheets nor fixtures are created anymore. If you want to customize it further, for example to use DataMapper and RSpec instead of Active Record and TestUnit, it's just a matter of adding their gems to your application and configuring your generators.
|
If we generate another resource with the scaffold generator, we can see that stylesheets, javascripts and fixtures are not created anymore. If you want to customize it further, for example to use DataMapper and RSpec instead of Active Record and TestUnit, it's just a matter of adding their gems to your application and configuring your generators.
|
||||||
|
|
||||||
To demonstrate this, we are going to create a new helper generator that simply adds some instance variable readers. First, we create a generator within the rails namespace, as this is where rails searches for generators used as hooks:
|
To demonstrate this, we are going to create a new helper generator that simply adds some instance variable readers. First, we create a generator within the rails namespace, as this is where rails searches for generators used as hooks:
|
||||||
|
|
||||||
|
@ -270,6 +271,7 @@ config.generators do |g|
|
||||||
g.template_engine :erb
|
g.template_engine :erb
|
||||||
g.test_framework :test_unit, fixture: false
|
g.test_framework :test_unit, fixture: false
|
||||||
g.stylesheets false
|
g.stylesheets false
|
||||||
|
g.javascripts false
|
||||||
g.helper :my_helper
|
g.helper :my_helper
|
||||||
end
|
end
|
||||||
```
|
```
|
||||||
|
@ -334,6 +336,7 @@ config.generators do |g|
|
||||||
g.template_engine :erb
|
g.template_engine :erb
|
||||||
g.test_framework :test_unit, fixture: false
|
g.test_framework :test_unit, fixture: false
|
||||||
g.stylesheets false
|
g.stylesheets false
|
||||||
|
g.javascripts false
|
||||||
end
|
end
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -352,6 +355,7 @@ config.generators do |g|
|
||||||
g.template_engine :erb
|
g.template_engine :erb
|
||||||
g.test_framework :shoulda, fixture: false
|
g.test_framework :shoulda, fixture: false
|
||||||
g.stylesheets false
|
g.stylesheets false
|
||||||
|
g.javascripts false
|
||||||
|
|
||||||
# Add a fallback!
|
# Add a fallback!
|
||||||
g.fallbacks[:shoulda] = :test_unit
|
g.fallbacks[:shoulda] = :test_unit
|
||||||
|
|
Loading…
Reference in a new issue