Custom class attributes problem

Hi.

Im creating a CRUD-extention for my ActionController. I am trying to
make a class (inside the Crudable-module) that contains the options set
for the extension. Like so:

  module Crudable
    # Extends the controller
    def self.included(controller)
      controller.helper_method( :render_form, :get_path_for,
:get_field_type )
      controller.extend(ClassMethods)
    end

    module ClassMethods # nodoc;
      def acts_crudable(options={})
        CrudOptions.new(self, options)
        self.send :include, ActionController::Crudable::InstanceMethods
      end
    end

    module InstanceMethods # nodoc;
      # All methods goes here...
    end
  end

Where the CrudOptions is the class that contains the options like
prefix, special view-paths etc. This class looks like this:

  class CrudOptions
    @options = {}
    def self.new(klass, options={})
      @options = {}
      options[:prefix] = nil unless options[:prefix]
      @options = options
    end

    def self.options(index)
      @options[index]
    end
  end

But I’m betting there is a smarter way to create that CrudOption-class.
But I can’t seem to get the hang of it. The problem is that the
CrudOption-class keeps the options set from the first call to the
new-method across new calls to the new-method. So calling the
acts_crudable(:prefix => ‘test’) and then calling acts_crudable() will
still keep the prefix ‘test’. How do I get around this.

If anyone can help me either fix the problem within the structure that
is there now, or can rewrite some of the code I would really appreciate
it!

Emil K. wrote:

Hi.

Im creating a CRUD-extention for my ActionController
[…]

Before you do this yourself, check out make_resourceful.

Best,

Marnen Laibow-Koser
http://www.marnen.org
[email protected]