Forum: Rails Engines development Stupid ruby controller question

Posted by 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?
Posted by 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
Posted by 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?
Posted by 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
Posted by 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
Posted by 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.
Posted by James Adam (Guest)
on 2006-01-13 00:20
(Received via mailing list)
Excellent. URL us so we can see it!

- james
Posted by 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
Please log in before posting. Registration is free and takes only a minute.
Existing account (Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
No account? Register here.