Overloading controller


#1

Hi,
The mailing list archives appear to be down currently, so I wasn’t
able to search them first.

What is the best practice for overloading an engine controller method?
I have Login Engine and User Engine installed. For example, I want
to override signup in user to show a different warning message than
“you need to login” (which I can accomplish by removing the guest
permission from the signup controller). Right now, I thought of one
way to do it:

  1. Allow the Guest role to access the signup method.

  2. Alias the existing signup method to open_signup:
    alias_method :open_signup, :signup

  3. Override the signup method to look something like this:
    def signup

    if !session[:user].nil?
    open_signup
    else
    flash[:notice] = “Please contact the webmaster for a login”
    access_denied
    end
    end
    end

The problem with this is that I now need an open_signup.rhtml
file…which would just end up being the same rhtml as signup.rhtml in
the LoginEngine!

It seems like I’m missing something here.

Thanks in advance for the help.

  • Sean

#2

On 21 Apr 2006, at 21:31, prplehaze wrote:

What is the best practice for overloading an engine controller method?

Create a controller in your OWN app/controllers directory called
user_controller.rb like this:

class UserController < ApplicationController
def signup
# your code goes here
end
end

and your method will over-ride anything in /vendor/plugins

You only need to put in the methods you wish to over-ride, and
remember your method will replace the existing one, so you probably
want to start with copying/pasting the existing method code and then
adapting it if you only want to make small changes.

  1. Allow the Guest role to access the signup method.

You need that. If you don’t, nobody will be able to ever signup.

  1. Alias the existing signup method to open_signup:
    alias_method :open_signup, :signup

You really don’t need to do that. Just create a signup method in your
own controller that does things

It seems like I’m missing something here.

What I’ve described above is actually mentioned in the Engines plugin
README, so I’d suggest you go read that, then the readme for
login_engine and user_engine and then you’ll know what you can get
away with.


Paul R.