Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Custom scaffold's controller template #818

apux opened this Issue Aug 31, 2013 · 7 comments


None yet
6 participants

apux commented Aug 31, 2013

I want to customize the scaffold's controller template in my rails project.


Is there any way to do that?

👍 I'd love to have this feature too. I was just trying to do the same thing but I'm pretty close to giving up. It looks like the Rspec generator overrides some stuff that makes it tricky to use your own template.

visoft commented May 14, 2014

Is this not possible to do? I've tried all sorts of paths in my Rails app, for example:


What's the location where these need to be?


cupakromer commented Jun 1, 2014

This is sort of a rails quirk. There needs to be a matching of what the library (gem) is using and where Rails looks for things.

If you want to override the standard controller generator template (i.e. used by rails g controller) it needs to be: lib/templates/rspec/controller/controller_spec.rb

To overwrite the template used by the scaffold (i.e. rails g scaffold) it needs to be: lib/templates/rspec/scaffold/controller_spec.rb.

I got this working successfully with RSpec 3 and Rails 4.1 using those paths.

@cupakromer cupakromer closed this Jun 1, 2014

visoft commented Aug 31, 2015

This seems to have changed. I'm using Rails 5 (master) with RSpec-Rails 3.1. The paths you provided @cupakromer, don't seem to work any longer. I have /lib/templates/rspec/scaffold/controller_spec.rb, but it's completely ignored.


JonRowe commented Sep 2, 2015

I believe Rails 5 isn't officially supported yet, because it's a significant refactor of Rails internally and will require significant work for us to support . @cupakromer knows more than I though

visoft commented Sep 2, 2015

I dropped down to Rails 4.2.4 and the paths seem to work fine.

Can someone please share the piece of code (or module) that does the template lookup? I've seen this question repeatedly asked (through the years) and knowing what lookups the template, might help. (I'd appreciate it :-) )

@esjee esjee added a commit to esjee/startupwichita.com that referenced this issue Oct 21, 2016

@esjee esjee overrides RSpec's controller spec generator
See rspec/rspec-rails#818 for more information.

@esjee esjee referenced this issue in StartupWichita/startupwichita.com Oct 21, 2016


Overrides RSpec's controller spec generator #80

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment