controllers inheritance

34 views
Skip to first unread message

Julien Ammous

unread,
Nov 2, 2013, 1:54:24 PM11/2/13
to scor...@googlegroups.com
Hi, I am continuing playing/torturing scorched and ran into another issue ;)
I am not sure yet if this is an issue or a design choice so I will start by asking here,
here what I tried:

https://gist.github.com/schmurfy/6248855

That's continuing with my idea of having a gem define the base class for the controller and
allowing the user to inherit from it and add more to it.

in this example the route defined in parent class seems to be completely ignored, is it a design choice ?

Tom Wardrop

unread,
Nov 3, 2013, 7:50:52 AM11/3/13
to scor...@googlegroups.com
Yep, that's by design.

In your scenario, if you want to define a base set of routes, you can do a couple of things. One option would be to simply define them on instantiation. This could be done by overriding #initialize (ensuring you call #super), or be using Ruby's `inherited` hook method.

Another option (which I personally prefer) would be to essentially set your base class as the `root` controller, mounting the sub-class to it as mapping. In other words, using sub-controllers (a controller mapped to a controller). I've left a comment on your gist showing this.

It all depends on exactly what you're trying to achieve, but there's definitely many potential solutions for this one.

Tom

Julien Ammous

unread,
Nov 4, 2013, 8:04:02 AM11/4/13
to scor...@googlegroups.com
That's what I thought, I will experiment with the available options and see which better suits my needs.

The idea for my application is that the gem is hat could be called a graphing framework, it provides the resources needed to create the final pages where the graph will be
but the views themselves are created by the user, to achieve this my current base class provides integration with sprockets along with the css/js dependencies allowing
the user to add its own to it.

I am still experimenting with the way it is designed but I am fairly happy with the current result, the paths to the standard resources is handled directly by a Rack::URLMap giving
access to sprockets resources and the scorched application is mounted at the root path.
The reason leading to the current question is that I know want to provide some static views (xhr) inside the base class.
Reply all
Reply to author
Forward
0 new messages