jeudi 24 mars 2016

Rails 3: How to override a Gem Method

version : Rails 3.2.22.2

I'm using Impressionist gem to track user activity. This gives me ActiveModel::MassAssignmentSecurity::Error I wan tot override the impression.rb module from the gen to use attr_accessible I tried 2 things -> 1: Create an impression.rb file under app/models

class Impression
  def hello
    "hello world"
  end
end

In initializer/impression.rb,

require 'impression'

when I try the following on console

a = Impression.first
a.hello

I get method not found error

2: I added the code in the initializezs/impression.rb file

Impression.class_eval do
    def hi
        puts 'you got me!'
    end
end

and I still go the same error as in point 1.

How can I effectively override the Gem model?

Aucun commentaire:

Enregistrer un commentaire