def belongs_to(*symbols, &block)
        options = symbols.extract_options!

        options.symbolize_keys!
        options.assert_valid_keys(:class_name, :parent_class, :instance_name, :param,
                                  :finder, :route_name, :collection_name, :singleton,
                                  :polymorphic, :optional, :shallow)

        optional    = options.delete(:optional)
        shallow     = options.delete(:shallow)
        polymorphic = options.delete(:polymorphic)
        finder      = options.delete(:finder)

        if self.parents_symbols.empty?
          include BelongsToHelpers
          helper_method :parent, :parent?
        end

        acts_as_polymorphic! if polymorphic || optional
        acts_as_shallow!     if shallow

        raise ArgumentError, 'You have to give me at least one association name.' if symbols.empty?
        raise ArgumentError, "You cannot define multiple associations with options: #{options.keys.inspect} to belongs to." unless symbols.size == 1 || options.empty?

        symbols.each do |symbol|
          symbol = symbol.to_sym

          if polymorphic || optional
            self.parents_symbols << :polymorphic unless self.parents_symbols.include?(:polymorphic)
            self.resources_configuration[:polymorphic][:symbols]   << symbol
            self.resources_configuration[:polymorphic][:optional] ||= optional
          else
            self.parents_symbols << symbol
          end

          self.resources_configuration[:self][:shallow] = true if shallow

          config = self.resources_configuration[symbol] = {}

          class_name = ''
          config[:parent_class] = options.delete(:parent_class) ||
            begin
              class_name = if options[:class_name]
                options.delete(:class_name)
              else
                namespace = self.name.deconstantize
                model_name = symbol.to_s.pluralize.classify

                klass = model_name
                while namespace != ''
                  new_klass = "#{namespace}::#{model_name}"
                  if new_klass.safe_constantize
                    klass = new_klass
                    break
                  else
                    namespace = namespace.deconstantize
                  end
                end

                klass = model_name if klass.start_with?('::')

                klass
              end
              class_name.constantize
            rescue NameError => e
              raise unless e.message.include?(class_name)
              nil
            end

          config[:singleton]       = options.delete(:singleton) || false
          config[:collection_name] = options.delete(:collection_name) || symbol.to_s.pluralize.to_sym
          config[:instance_name]   = options.delete(:instance_name) || symbol
          config[:param]           = options.delete(:param) || :"#{symbol}_id"
          config[:route_name]      = options.delete(:route_name) || symbol
          config[:finder]          = finder || :find
        end

        if block_given?
          class_eval(&block)
        else
          create_resources_url_helpers!
        end
      end
def belongs_to(*symbols, &block)
        options = symbols.extract_options!

        options.symbolize_keys!
        options.assert_valid_keys(:class_name, :parent_class, :instance_name, :param,
                                  :finder, :route_name, :collection_name, :singleton,
                                  :polymorphic, :optional, :shallow)

        optional    = options.delete(:optional)
        shallow     = options.delete(:shallow)
        polymorphic = options.delete(:polymorphic)
        finder      = options.delete(:finder)

        if self.parents_symbols.empty?
          include BelongsToHelpers
          helper_method :parent, :parent?
        end

        acts_as_polymorphic! if polymorphic || optional
        acts_as_shallow!     if shallow

        raise ArgumentError, 'You have to give me at least one association name.' if symbols.empty?
        raise ArgumentError, "You cannot define multiple associations with options: #{options.keys.inspect} to belongs to." unless symbols.size == 1 || options.empty?

        symbols.each do |symbol|
          symbol = symbol.to_sym

          if polymorphic || optional
            self.parents_symbols << :polymorphic unless self.parents_symbols.include?(:polymorphic)
            self.resources_configuration[:polymorphic][:symbols]   << symbol
            self.resources_configuration[:polymorphic][:optional] ||= optional
          else
            self.parents_symbols << symbol
          end

          self.resources_configuration[:self][:shallow] = true if shallow

          config = self.resources_configuration[symbol] = {}

          class_name = ''
          config[:parent_class] = options.delete(:parent_class) ||
            begin
              class_name = if options[:class_name]
                options.delete(:class_name)
              else
                namespace = self.name.deconstantize
                model_name = symbol.to_s.pluralize.classify

                klass = model_name
                while namespace != ''
                  new_klass = "#{namespace}::#{model_name}"
                  if new_klass.safe_constantize
                    klass = new_klass
                    break
                  else
                    namespace = namespace.deconstantize
                  end
                end

                klass = model_name if klass.start_with?('::')

                klass
              end
              class_name.constantize
            rescue NameError => e
              raise unless e.message.include?(class_name)
              nil
            end

          config[:singleton]       = options.delete(:singleton) || false
          config[:collection_name] = options.delete(:collection_name) || symbol.to_s.pluralize.to_sym
          config[:instance_name]   = options.delete(:instance_name) || symbol
          config[:param]           = options.delete(:param) || :"#{symbol}_id"
          config[:route_name]      = options.delete(:route_name) || symbol
          config[:finder]          = finder || :find
        end

        if block_given?
          class_eval(&block)
        else
          create_resources_url_helpers!
        end
      end
Defines that this controller belongs to another resource.

   belongs_to :projects

 == Options

 * <tt>:parent_class</tt> - Allows you to specify what is the parent class.

     belongs_to :project, :parent_class => AdminProject

 * <tt>:class_name</tt> - Also allows you to specify the parent class, but you should
                          give a string. Added for ActiveRecord belongs to compatibility.

 * <tt>:instance_name</tt> - The instance variable name. By default is the name of the association.

     belongs_to :project, :instance_name => :my_project

 * <tt>:finder</tt> - Specifies which method should be called to instantiate the parent.

     belongs_to :project, :finder => :find_by_title!

   This will make your projects be instantiated as:

     Project.find_by_title!(params[:project_id])

   Instead of:

     Project.find(params[:project_id])

 * <tt>:param</tt> - Allows you to specify params key to retrieve the id.
                     Default is :association_id, which in this case is :project_id.

 * <tt>:route_name</tt> - Allows you to specify what is the route name in your url
                          helper. By default is association name.

 * <tt>:collection_name</tt> - Tell how to retrieve the next collection. Let's
                               suppose you have Tasks which belongs to Projects
                               which belongs to companies. This will do somewhere
                               down the road:

      @company.projects

   But if you want to retrieve instead:

      @company.admin_projects

   You supply the collection name.

 * <tt>:polymorphic</tt> - Tell the association is polymorphic.

 * <tt>:singleton</tt> - Tell it's a singleton association.

 * <tt>:optional</tt> - Tell the association is optional (it's a special
                        type of polymorphic association)