Anybody know an easy way to redefine scaffold_path globally rather than having to override it on a controller by controller basis? Ta Sean O''Halpin _________________________________________________________________ Stay in touch with absent friends - get MSN Messenger http://www.msn.co.uk/messenger
Hello Sean, Sean O''Halpin wrote:> Anybody know an easy way to redefine scaffold_path > globally rather than having to override it on a controller > by controller basis?I suspect you want to overwrite or change the ActionController::Scaffolding::ClassMethods::scaffold_path method. It reads def scaffold_path(template_name) File.dirname(__FILE__) + "/templates/scaffolds/" + template_name + ".rhtml" end On my installtion this method sits in /usr/local/lib/ruby/gems/1.8/gems/actionpack-0.9.5/lib/action_controller/scaffolding.rb Good luck, Sascha Ebach
Thanks Sascha - I should have been clearer as to what exactly I was looking for. I was wondering if there were an ~easy~ way to override scaffold_path without having to change library code or override the whole definition of scaffold. Because the scaffold method adds these methods dynamically to the controller, you can''t simply override only the scaffold_path method anywhere (it seems) as the act of adding the scaffold will redefine whatever method you put in place (it does a module_eval inside your controller). So it appears that the only way to change the default scaffold_path is to either: 1) redefine the library definition (which will change the default path for the whole installation!), 2) change it on a controller by controller basis by redefining the scaffold_path after calling scaffold, e.g. scaffold :post def scaffold_path "/web/app/scaffold/templates" end or 3) override the whole scaffold definition I''ll probably go for 3). I was just wondering if there were an easier way I was missing. Regards, Sean O''Halpin _________________________________________________________________ Express yourself with cool new emoticons http://www.msn.co.uk/specials/myemo
Sean O''Halpin wrote:> Thanks Sascha - I should have been clearer as to what exactly I was > looking for. > > I was wondering if there were an ~easy~ way to override scaffold_path > without > having to change library code or override the whole definition of scaffold. > Because the scaffold method adds these methods dynamically to the > controller, you can''t > simply override only the scaffold_path method anywhere (it seems) > as the act of adding the scaffold will redefine whatever method > you put in place (it does a module_eval inside your controller). > > So it appears that the only way to change the default scaffold_path is > to either: > > 1) redefine the library definition (which will change the default path > for the whole installation!),Indeed, not so good.> 2) change it on a controller by controller basis by redefining the > scaffold_path after calling scaffold, e.g. > > scaffold :post > def scaffold_path "/web/app/scaffold/templates" end > > or > 3) override the whole scaffold definition > > I''ll probably go for 3). > > I was just wondering if there were an easier way I was missing.Have you tried overriding scaffold_path in AbstractApplicationController? If you want to change the path (or any setting that is) *per* application, than this should be the prefered way. -- Sascha Ebach
Maybe try changing the scaffold_path on the application controller. http://www.rubyonrails.org/show/AbstractApplicationController Micah Calabrese On Tue, 23 Nov 2004 12:45:29 +0000, Sean O''Halpin <seanonrails-PkbjNfxxIARBDgjK7y7TUQ@public.gmane.org> wrote:> Thanks Sascha - I should have been clearer as to what exactly I was looking > for. > > I was wondering if there were an ~easy~ way to override scaffold_path > without > having to change library code or override the whole definition of scaffold. > Because the scaffold method adds these methods dynamically to the > controller, you can''t > simply override only the scaffold_path method anywhere (it seems) > as the act of adding the scaffold will redefine whatever method > you put in place (it does a module_eval inside your controller). > > So it appears that the only way to change the default scaffold_path is to > either: > > 1) redefine the library definition (which will change the default path for > the whole installation!), > 2) change it on a controller by controller basis by redefining the > scaffold_path after calling scaffold, e.g. > > scaffold :post > def scaffold_path "/web/app/scaffold/templates" end > > or > 3) override the whole scaffold definition > > I''ll probably go for 3). > > I was just wondering if there were an easier way I was missing. > > Regards, > > Sean O''Halpin > > _________________________________________________________________ > Express yourself with cool new emoticons http://www.msn.co.uk/specials/myemo > > > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >