“Controllers: You can’t directly write a controller plugin, but you
can write a generator that copies a controller to your app/controllers
directory. Intermediate difficulty.”
I think that’s pretty much the answer I was hoping for Jason! So the
article is wrong and yes you can write controller plugins… thought
that was odd!
I have a site/project where I use a controller base class that handles
all the standard REST methods (new, show, edit, etc…) in a fairly
generic way. It would certainly take some work but I thought it might
be nice to share it as a plugin… at least for my own projects, and
others if there is any interest.
I have looked a bit but haven’t seen anything like it. Is there a
plugin that already does something similar?
I think that’s pretty much the answer I was hoping for Jason! So the
article is wrong and yes you can write controller plugins… thought
that was odd!
Yes and no. What the article is saying is that you can’t have
foo_controller in your plugin, install your plugin and then try to
access 应用宝官网-全网最新最热手机应用游戏下载
I think that there is stuff afoot so that you can specify the paths
searched for views & controllers, but out of the box it won’t work.
What you can of course do is a generator, provide modules for
controllers or extend ActionController with macros and so on.
Thanks for setting me down the right path here guys… It appears to
be relatively straight forward.
CHH - I’m only vaguely familiar with activescaffold … I was really
trying to avoid a generator … unless I’m misunderstanding they
typically generate a lot of very similar code over and over … this
is for more than just admin stuff too:-)
I really just want to be able to inherit functionality into my
controllers.
foo_controller in your plugin, install your plugin and then try to
access 应用宝官网-全网最新最热手机应用游戏下载
I think that there is stuff afoot so that you can specify the paths
searched for views & controllers, but out of the box it won’t work.
What you can of course do is a generator, provide modules for
controllers or extend ActionController with macros and so on.
Hmmm, looks like you already can. Try adding your load paths to:
MyController.template_root
ActionController::Routing.controller_paths
Dependencies.load_paths
Demo:
$ cat vendor/plugins/test_plugin/init.rb
config.after_initialize do
path = File.expand_path(‘app/controllers’, File.dirname(FILE))
ActionController::Routing.controller_paths << path
Dependencies.load_paths << path
end
$ cat
vendor/plugins/test_plugin/app/controllers/test_plugin_controller.rb
class TestPluginController < ApplicationController
self.template_root = File.expand_path(‘…/views’,
File.dirname(FILE))
def test
end
end
$ cat vendor/plugins/test_plugin/app/views/test_plugin/test.rhtml
hi
$ script/console
Loading development environment.
app.get(‘/test_plugin/test’); puts app.response.body
hi
=> nil
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.