Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Custom Views Scaffolding in Rails Engines

I'm trying to get custom scaffolding working from my engine.

I followed some tutorial on customizing Rails 3.2 scaffolding in a normal Rails App and put my customized templates in the engines /lib/templates/erb/scaffold directory but they don't get picked up by the app that includes the engine. Any suggestions?

Update: I also tried to override the Rails ScaffoldGenerator's source_path and tried some other paths to put my template in, like: lib/rails/generators/erb/scaffold/templates

like image 450
wintersolutions Avatar asked Feb 17 '23 14:02

wintersolutions


1 Answers

zarazan's answer got me most of the way there, but there are a couple of things wrong with it. Here's what worked for me:

class Engine < Rails::Engine

  config.generators do |g|
    g.templates.unshift File::expand_path('../../templates', __FILE__)
  end

end

Note that this goes in the generators section, not app_generators, and that the path is slightly different.

Also, I think the correct path to store your templates is lib/templates/erb/scaffold, optionally replacing erb with whatever language you are using (like haml or slim.) I know this works for slim. The file names are {_form,edit,index,new,show}.html.erb.

like image 74
tmandry Avatar answered Feb 27 '23 14:02

tmandry