Sinatra Authentication with MongoMapper Support

1 Jan

Added support for MongoMapper in the sinatra-authentication gem. Grab it from http://github.com/britg/sinatra-authentication.

Be sure to require mongo_mapper before sinatra-authentication and everything should work peachy keen.

require 'sinatra/base'
require 'mongo_mapper'
require 'sinatra-authentication'
  • Hey, I've come across what I think is a bug with the mongo_mapper support for sinatra-authentication:

    class MmUser
    many :things
    end

    class Thing
    include MongoMapper::EmbeddedDocument
    key :name, String
    end

    # inside sinatra
    current_user.things # Works as expected

    current_user.things << Thing.new(:name => 'My Thing')
    current_user.save # Doesn't add the new thing to the current_user

    c_u = MmUser.find_by_id(current_user.id)
    c_u.things << Thing.new(:name => 'My Thing')
    c_u.save # *does* add the new thing as expected

    I hope this is useful!
  • Hope the complete code is available?
blog comments powered by Disqus