Forum: Rails Engines development Stupid ruby controller question

Efe398b3b5436b0a8d4430090e8f86ea?d=identicon&s=25 Seth (Guest)
on 2006-01-05 10:56
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?
05d703f649ef1d07e78d7b479fb4c4ac?d=identicon&s=25 James Adam (Guest)
on 2006-01-05 11:08
(Received via mailing list)
(this post is more suitable for engine-users btw - engine-developers
is more for patches to the Engines plugin.... but anyway.... :)

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
Efe398b3b5436b0a8d4430090e8f86ea?d=identicon&s=25 Seth (Guest)
on 2006-01-05 21:43
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?
05d703f649ef1d07e78d7b479fb4c4ac?d=identicon&s=25 James Adam (Guest)
on 2006-01-06 11:44
(Received via mailing list)
This is a bug - expect a new release of the Engines plugin in a few
hours... Thanks! :)

- james
05d703f649ef1d07e78d7b479fb4c4ac?d=identicon&s=25 James Adam (Guest)
on 2006-01-12 12:16
(Received via mailing list)
The latest release of the Engines plugin should solve this - is it
working for you?

- james

---------- Forwarded message ----------
From: James Adam <james.adam@gmail.com>
Date: Jan 6, 2006 10:44 AM
Subject: Re: [Engine-developers] Stupid ruby controller question
To: engine-developers@lists.rails-engines.org


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

- james
Efe398b3b5436b0a8d4430090e8f86ea?d=identicon&s=25 Subimage (Guest)
on 2006-01-13 00:13
James Adam 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.
05d703f649ef1d07e78d7b479fb4c4ac?d=identicon&s=25 James Adam (Guest)
on 2006-01-13 00:20
(Received via mailing list)
Excellent. URL us so we can see it!

- james
Efe398b3b5436b0a8d4430090e8f86ea?d=identicon&s=25 Subimage (Guest)
on 2006-01-14 01:18
James Adam 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)

http://games.skunkstudios.com
http://www.genselect.com
This topic is locked and can not be replied to.