Stupid ruby controller question

Thanks for all the help so far guys…here’s another one for the smart
engine devs…

Let’s say I have a MainController in my engine…and it has 4 actions
inside there.

Now let’s say I want to inherit that MainController in my regular
application, and override one of the actions…

How would I go about doing that? It seems when I place MainController in
my application it overrides the one in my engine folder by default.

What’s the appropriate way to do this? Mixins? Inheritance?

(this post is more suitable for engine-users btw - engine-developers
is more for patches to the Engines plugin… but anyway… :slight_smile:

If you have something like this in your engine:

RAILS_ROOT/
vendor/
plugins/
my_engine/
app/
controllers/
main_controller.rb
(with the contents:)
class MainController < ApplicationController
def method1() puts “hello” end
def method2() puts “ruby” end
def method3() puts “rocketh” end
end

… if you just wanted to change the behaviour of, say,
MainController#method3, you should only need the following:

RAILS_ROOT/
app/
controllers/
main_controller.rb
(containing:)
class MainController < ApplicationController
def method3() puts “like, y’know, totally rules” end
end

Any methods defined in corresponding controllers of your main /app
directory will override those in the engine. Is this what you’ve done?

  • james

Sorry for the off-topic then…

What you describe is exactly what I’m trying…well with a little twist.
It’s not the MainController, its one of my controllers thats a subclass.


RAILS_ROOT/vendor/plugins/my_engine/app/controllers/admin/orders_controller.rb

class Admin::OrdersController < Admin::BaseController
def index
…do something
end

def show

end

def …

end
end


RAILS_ROOT/app/controllers/admin/orders_controller.rb

class Admin::OrdersController < Admin::BaseController
def ship_orders
…do something
end
end

What’s going on is that when I try to hit the index action defined in my
engine, Rails says it doesn’t exist.

“Unknown action - No action responded to index”

Could subclassing my Admin::BaseController be causing the problem? I’m
guessing maybe engines aren’t setup to deal with this?

This is a bug - expect a new release of the Engines plugin in a few
hours… Thanks! :slight_smile:

  • james

The latest release of the Engines plugin should solve this - is it
working for you?

  • james

---------- Forwarded message ----------
From: James A. [email protected]
Date: Jan 6, 2006 10:44 AM
Subject: Re: [Engine-developers] Stupid ruby controller question
To: [email protected]

This is a bug - expect a new release of the Engines plugin in a few
hours… Thanks! :slight_smile:

  • james

James A. wrote:

The latest release of the Engines plugin should solve this - is it
working for you?

  • james

Definitely. Just deployed my production app to Dreamhost about an hour
ago.

Excellent. URL us so we can see it!

  • james

James A. wrote:

Excellent. URL us so we can see it!

  • james

I didn’t design it, so I’m not really “proud” of it per say…That and
Dreamhost is extremely slow.

But I will plug 2 of my other sites that are running on the same engine
code at the moment (which I designed from top to bottom)