activeadmin / activeadmin-mongoid

ActiveAdmin hacks to support Mongoid
MIT License
192 stars 210 forks source link

Broken for Rails 4.2 - here's how to fix #97

Closed danbartlett closed 7 years ago

danbartlett commented 9 years ago

After upgrading to rails 4.2 we started experiencing Undefined method column_for_attribute

I eventually came across https://github.com/elia/activeadmin-mongoid/issues/95 which lead me to this pull request https://github.com/elia/activeadmin-mongoid/pull/96/files

I tried using:

gem 'activeadmin-mongoid', github: 'pencilcheck/activeadmin-mongoid', branch: 'patch-1'

Which fixed my first error, but then raised another error about _ransack not being available. So I looked at the pull request again, and tried re-adding what pencilcheck removed:

module ActiveAdmin
  module Filters
    module FormtasticAddons

      # The resource class, unwrapped from Ransack
      def klass
        @object.klass
      end

    end
  end
end

After adding this in to one of my models, everything works again!

danbartlett commented 9 years ago

@pencilcheck, any thoughts?

pencilcheck commented 9 years ago

@danbartlett I believe you would also want to include master branch to activeadmin/activeadmin.

e.g. gem 'activeadmin', github: 'activeadmin', branch: 'master'

But including a moving target is dangerous, so I pick one commit

e.g. gem 'activeadmin', github: 'activeadmin', ref: '54bed'

Also, I have a fork of ransack that adds embedded documents in this PR: https://github.com/activerecord-hackery/ransack/pull/498

If you are interested just include this before activeadmin and activeadmin-mongoid: gem 'ransack', github: 'pencilcheck/ransack', branch: 'patch-1'

Hope that works for you.

pencilcheck commented 9 years ago

If you are getting an error about "$oid", maybe this snippet from this issue plataformatec/devise#2949 would help:

HACK FOR DEVISE 3.2.4

def self.serialize_into_session(record) [record.id.to_s, record.authenticatable_salt] end Put it in the user class used for devise

pisaq commented 9 years ago

It is working for me so far. Extra much appreciate :)

mzdemezer commented 9 years ago

I managed to solve Undefined method column_for_attribute by adding initializer:

module Mongoid
  module Document
    def column_for_attribute(attribute)
      type = fields[attribute.to_s].type.to_s.underscore.split('/').last.to_sym
      Struct.new(:type).new(type)
    end
  end
end

I hope this helps.