overriding gem controllers and views

I can override any gem’s controllers and views by creating them in my app?

Yes, you can







All the original file can be founded inside railties folder (bundle show railties)

You can also add views editing scaffold_generator.rb



Sorry I’ve seen now the word ‘gems’ My instructions are to make override of scaffold generator.


Right. It's even easier for a gem. Just put your templates in the same relative place within your normal rails views or controllers, properly named, and they will "shadow" the version within the gem. In most things in Rails, "nearest wins". Gems insert their code into the Rails lookup path *after* the core application code, not before. So if you add code to the core, it will be found before the gem's code is, and Rails will stop looking at that point.

I just dealt with this last night, when I overrode the Thredded gem to make the breadcrumbs work the way I needed them to. All I had to do was add this folder:


and add the _breadcrumbs.html.erb file to that folder, and I had complete control over that one file (without needing to shadow every other part of the gem).