Before a few days i manage to overwrite the migration template adding collation and encoding info.
I have create a new file here:
"lib/templates/active_record/model/migration.rb" so you may have to adjust the the folder name for the scaffolding to work.
I have found the right folder name for the controller/view scaffolding, but at my village PC so i don't have the right folder name here, sorry ;-). One problem that i have found is that the lis of files that the generator makes is hardcoded. So not an easy way to have an _item.html.erb partial other than to copy and rename the generator inside lib/generators.
Hey Ryan nice video, I learned some more tips about that now.
About replace scaffolds I think the problem is only the path.
I use here for haml -> /lib/generators/haml/scaffold/templates/index.html.haml and other.
I think you need do the same for erb: /lib/generators/erb/scaffold/templates/index.html.erb
Kind of related to the topic of generators, I've been working on a gem for quick project creation from templates (not just Rails, any kind of project) You can check it out (pun fully intended) on github:
http://github.com/i0n/jumpstart
Yes, it was a bug. When you required rails/generators in config/application.rb, it was being required too early and then Rails::Generators could not copy part of the configuration set in your application.
This was fixed and the guide updated. However, as David Trasbo pointed above, the best solution is to use config.generators.fallbacks. You usually don't want to require "rails/generators" because it would force generators to be loaded in production (for instance).
Nice screencast! I wonder why you never use haml instead of erb. I switched a long time ago and don't regret it at all. It's so much nicer and cleaner to use haml instead of erb. In the latest version of the gem you can even do multiline commands which was a bit awkward to achieve before. Sorry if this is a bit off topic, it just popped into my mind... ;-)
Ryan, I love your screencasts, and they have helped me enormously in getting to grips with Rails more quickly than I otherwise would.
However, I can't help feeling that Rails 3 is still (at least) months away from being a version that can be properly utilised by serious developers. I know your railscasts are meant to be at the forefront of what is best in the ROR community, but clearly (to me) the number of necessary workarounds indicated by your vids - and many others on the same subject (upgrading to Rails 3) - leave me with a no-brainer decision on whether to upgrade production systems to Rails 3 - NFW.
Great screencast per usual. I've started using my own templates for scaffolding and found it makes life just that much simpler. I was wondering if anyone has tried changing the rails new generator so that each new project creates the same lib/templates directory. Figure this kinda makes your nifty-generators a little outdated.
Cheers.
This didn't work with the non-standard rails3-generators for me, but putting the line
require 'rails/generators'
into a file (named anything) within config/initializers fixed it. I get errors when it tries to created the helpers and stylesheets for some reason, though (error shoulda [not found] it says, though it finds it for the test).
A hint for anyone stuck trying to override the default model when using the scaffold generator: make a template file in lib/templates/active_record/model/model.rb
Is there a way to tell test_unit to setup factory_girl in the functional tests?
Using g.fixture_replacement :factory_girl
still puts by default fixture alike setup in the controller test, example:
class PostsControllerTest < ActionController::TestCase
setup do
@post = posts(:one)
end
...
end
Is it possible to use the attributes variable in the controller when using the scaffold generator? I would like to automatically generate two put actions 'up' and 'down' in my controller, if the generated resource has a position attribute. But I get an error saying it does not find the attribute variable. Any idea?
Before a few days i manage to overwrite the migration template adding collation and encoding info.
I have create a new file here:
"lib/templates/active_record/model/migration.rb" so you may have to adjust the the folder name for the scaffolding to work.
I have found the right folder name for the controller/view scaffolding, but at my village PC so i don't have the right folder name here, sorry ;-). One problem that i have found is that the lis of files that the generator makes is hardcoded. So not an easy way to have an _item.html.erb partial other than to copy and rename the generator inside lib/generators.
Keep your good job Rayan
The customized scaffold template is not used because you require 'rails/generators' at the end of the application.rb file.
Thanks again!
Here are some nice resources/blog posts of almost everything with Rails 3 generators
http://www.viget.com/extend/
Hey Ryan nice video, I learned some more tips about that now.
About replace scaffolds I think the problem is only the path.
I use here for haml -> /lib/generators/haml/scaffold/templates/index.html.haml and other.
I think you need do the same for erb: /lib/generators/erb/scaffold/templates/index.html.erb
You used lib/templates instead of lib/generators
Kind of related to the topic of generators, I've been working on a gem for quick project creation from templates (not just Rails, any kind of project) You can check it out (pun fully intended) on github:
http://github.com/i0n/jumpstart
Jari is right. It is easy to fix. Use
config.generators do |g|
...
g.fallbacks[ :shoulda ] = :test_unit
end
instead
Great work as usual!
Alfredo Ribeiro, I have tried the route lib/generators/erb/scaffold/templates/index.html.erb
for erb and it didn't work.
Hey Ryan,
Yes, it was a bug. When you required rails/generators in config/application.rb, it was being required too early and then Rails::Generators could not copy part of the configuration set in your application.
This was fixed and the guide updated. However, as David Trasbo pointed above, the best solution is to use config.generators.fallbacks. You usually don't want to require "rails/generators" because it would force generators to be loaded in production (for instance).
Sorry for the issue! :)
Nice screencast! I wonder why you never use haml instead of erb. I switched a long time ago and don't regret it at all. It's so much nicer and cleaner to use haml instead of erb. In the latest version of the gem you can even do multiline commands which was a bit awkward to achieve before. Sorry if this is a bit off topic, it just popped into my mind... ;-)
Ryan, I love your screencasts, and they have helped me enormously in getting to grips with Rails more quickly than I otherwise would.
However, I can't help feeling that Rails 3 is still (at least) months away from being a version that can be properly utilised by serious developers. I know your railscasts are meant to be at the forefront of what is best in the ROR community, but clearly (to me) the number of necessary workarounds indicated by your vids - and many others on the same subject (upgrading to Rails 3) - leave me with a no-brainer decision on whether to upgrade production systems to Rails 3 - NFW.
This inspired me to write a blog post on getting Rails 3, RSpec, and Cucumber all set up and working together:
http://blog.notahat.com/posts/43
Great screencast per usual. I've started using my own templates for scaffolding and found it makes life just that much simpler. I was wondering if anyone has tried changing the rails new generator so that each new project creates the same lib/templates directory. Figure this kinda makes your nifty-generators a little outdated.
Cheers.
This didn't work with the non-standard rails3-generators for me, but putting the line
require 'rails/generators'
into a file (named anything) within config/initializers fixed it. I get errors when it tries to created the helpers and stylesheets for some reason, though (error shoulda [not found] it says, though it finds it for the test).
A hint for anyone stuck trying to override the default model when using the scaffold generator: make a template file in lib/templates/active_record/model/model.rb
Thanks for the great post!
Is there a way to tell test_unit to setup factory_girl in the functional tests?
Using g.fixture_replacement :factory_girl
still puts by default fixture alike setup in the controller test, example:
class PostsControllerTest < ActionController::TestCase
setup do
@post = posts(:one)
end
...
end
I don't know if this is solved. You can put the index.html.erb (last part of the video) inside lib/templates/erb/scaffold/
Thanks Srinivas, this worked for me. My bellowing "Yeeeeesssss" is still reverberating through our home office.
Is it possible to use the attributes variable in the controller when using the scaffold generator? I would like to automatically generate two put actions 'up' and 'down' in my controller, if the generated resource has a position attribute. But I get an error saying it does not find the attribute variable. Any idea?
it's a good post