Evgeniy Dolzhenko wrote:

> 
> 3. Now I would like to have some super-method available at fixed URL
> which will decide based on user settings which page to serve to the
> user and call the appropriate controller.

Personally, I would just write a controller that, after choosing the 
proper controller, just redirects to the URL for that controller. Any 
reason not to do that?


> But this in my thinking brings another question - how to reuse just
> code along with views? There is Cells plugin
> http://github.com/apotonick/cells_examples/tree/master but I'm sort of
> wary about bringing this in, especially since ActionControllers
> already have what I need, i.e. the code with attached views.
> 
> Moving the shared code to the module will work but only to the some
> extent since there will be no conventional place for templates, no
> simple way to define filters, etc.


I'm not quite sure what you mean?  There's no official built-in way to 
re-use code amongst controllers. But you can use any OO technique you 
want.  Sure, you can put it in a module.  Since you'll be including the 
module in existing controllers, conventional place for templates and 
filters etc will remain pretty much the same.  Code in a module ends up 
getting executed 'as if' it was in the class that included it, right? 
It'll still look for templates in the same places as usual. If you have 
views shared between different controllers, just make a 'shared' sub-dir 
in your views dir, and refer to the template specifically as 
'shared/template_name' instead of just 'template_name'.  Or you can call 
it anything you want, not just 'shared'.  This technique works for 
sharing view templates between controllers regardless of whether you 
need to share logic between controllers or not.

I think I'd use a module for shared code between controllers. You could 
also use a common superclass for multiple controllers, but I don't think 
I'd do that. You could also put common code in an entirely seperate 
library class, that the controller gets a reference to: 
@more_controller_logic = MyClass.new ; 
@more_controller_logic.do_something.  Depending on what it is you want 
to do, that may or may not be convenient.

I think a module is probably what you want. If there's a specific kind 
of logic you want to put in your module shared between controllers that 
for some reason doesn't seem to be working... try asking with that 
specific example. I think a module should work fine.

Jonathan
-- 
Posted via http://www.ruby-forum.com/.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to