Constants in PlugIns/Mixins

Hello,

currently I’m writing on a PlugIn for my Project.
In this PlugIn I MUST include two Constants. But where do I include
them?

Here’s the Code of the PlugIn:

Status

module ___Plugins
module Internal #:nodoc:
module Status #:nodoc:

  def self.included(base)
    base.extend ClassMethods
  end

  module ClassMethods
    def status
      include ___Plugins::Internal::Status::InstanceMethods
      extend ___Plugins::Internal::Status::SingletonMethods

      attr_accessor :public_state
      attr_accessor :commentable_state

      validates_inclusion_of  :public_state,      :in =>

PUBLIC_STATE
validates_inclusion_of :commentable_state, :in =>
COMMENTABLE_STATE
end

    PUBLIC_STATE = {
                'closed'        => 'Geschlossen',
                'password_safe' => 'Password geschützt',
                'friends_only'  => 'Nur für Freunde offen',
                'opened'        => 'Offen'
              }

    COMMENTABLE_STATE = {
                'world'         => 'Jeder',
                'internal'      => '___.de Nutzer',
                'friends'       => 'Nur Freunde',
                'nobody'        => 'Keiner'
              }
  end

  # This module contains instance methods
  module InstanceMethods
    def can_see?(user)
      return false if self.user.is_ignored?(user)

      return true if self.public_state == "opened"
      return true if self.public_state == "password_safe"
      return true if self.public_state == "friends_only"  &&

self.user.is_friend?(user)

      return false
    end

    def can_comment?(user)
      return false if self.user.is_ignored?(user)

      return true if self.commentable_state == "world"
      return true if self.commentable_state == "internal" && (user

&& User.find_by_id(user.id))
return true if self.commentable_state == “friends” &&
self.user.is_friend?(user)
end
end

  # This module contains class methods
  module SingletonMethods

  end

end

end
end

Sorry but I have to mask the domain name with underscores.
The two constants are PUBLIC_STATE and COMMENTABLE_STATE.

When I run the Controller Action I get the following error message:
“uninitialized constant PUBLIC_STATE”

Source:
5:

<%= h album.description %>

6:

http://<%=
current_user.login %>.___.de/photoalbum/show/<%= album.permalink
%>


7:


8: Status: <%= PhotoAlbum::PUBLIC_STATE[album.public_state]
%>

9: Kommentieren: <%=
PhotoAlbum::COMMENTABLE_STATE[album.commentable_state] %>
10:


11:

But why? I mixed the module ___::Internal::Status into my PhotoAlbum
model class.

Greets
Christoph

Sorry for my bad english, but I am German.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs