18

I have a portfolio website built in Sinatra. I haven't worked on it for a while, been doing some Rails. I updated my gem list yesterday by running 'gem update'. I don't know if this has anything to do with that, but I started working on the portfolio website again today and I've been getting some deprecation warnings.

DEPRECATION WARNING: The InstanceMethods module inside ActiveSupport::Concern will be no longer included automatically. Please define instance methods directly in Work instead. (called from include at /Users/joris/Desktop/sinatra/portfolio/models/work.rb:2)

I'm not sure how to fix this and when I run the application it doesn't work anymore.. going to my routes just returns the Sinatra 404 page. (Also, isn't ActiveSupport part of Rails? Why is this coming up in my Sinatra app..)

The file it mentions in the error is work.rb:

class Work
  include MongoMapper::Document
     key :title, String
     key :url, String
     key :filename, String
     key :file, String
     key :description, String

    timestamps!
end

This is my main file (portfolio.rb):

require "sinatra"
require 'twitter'
require 'RedCloth'
require 'html_truncator'
require 'digest/md5'

class Portfolio < Sinatra::Application

  require_relative 'config/init'
  require_relative 'helpers/init'
  require_relative 'models/init'
  require_relative 'routes/init'

The models init file (which calls the work.rb file) has these contents:

require 'mongo_mapper'

MongoMapper.connection = Mongo::Connection.new('lalaland.com', 10070)
MongoMapper.database = 'hello'
MongoMapper.database.authenticate('lalala', 'hello')

require_relative 'post'
require_relative 'work'

EDIT: Just saw I'm also getting it for models/post.rb

DEPRECATION WARNING: The InstanceMethods module inside ActiveSupport::Concern will be no longer included automatically. Please define instance methods directly in Post instead. (called from include at /Users/joris/Desktop/sinatra/portfolio/models/post.rb:2)

Joris Ooms
  • 11,880
  • 17
  • 67
  • 124

2 Answers2

41

Somewhere in your app (or its dependencies) you're doing

module Blah
  extend ActiveSupport::Concern
  module InstanceMethods
    def foo
    end
  end
  ...
end

and Active Support is telling you to do

module Blah
  extend ActiveSupport::Concern
  def foo
  end
end

You're right that Active Support is part of Rails, but like Active Record it can also be used without the rest of rails. Mongo mapper uses it for example, and at a cursory glance it uses the deprecated InstanceMethods idiom in a bunch of places

Frederick Cheung
  • 83,189
  • 8
  • 152
  • 174
  • I'm not doing that anywhere. However the code it errors on (my models) are including MongoMapper::Document. Could it perhaps be a 'bug' in MongoMapper? Thanks for the reply :) – Joris Ooms Dec 30 '11 at 23:17
  • Mongo mapper does seem to be using the newly deprecated form. – Frederick Cheung Dec 30 '11 at 23:30
  • I removed all references to mongo_mapper and my page now loads. Guess i'll have to wait for an update or look for an alternative. Thanks :) – Joris Ooms Dec 30 '11 at 23:55
  • If I were you I'd try pinning the active support version to 3.1.3 – Frederick Cheung Dec 31 '11 at 10:39
  • 1
    This breaks all related tests for me. Shame. I can't move the code to the class itself because that's the point why I'm defining it in the module. So now I have to rename InstanceMethods to MyInstanceMethods and perform `def self.included(base) base.send :include, MyInstanceMethods end` manually? Really? Is there better solution? – Dalibor Filus Jan 21 '12 at 14:16
3

It looks like this was patched earlier this month in the mongo_mapper gem, so I would expect the fix to make it into the next release:

https://github.com/jnunemaker/mongomapper/commit/d2333d944ce6ae59ecab3c45e25bbed261f8180e

GroovyCakes
  • 361
  • 2
  • 12