joakimk/minimapper

Error `protected_attributes' on Rails 4

Closed this issue · 4 comments

Hi,

I'm in trouble when I try to use Minimapper with ActiveRecord 4.0.1 (with or without Rails).

I got the error:

Failure/Error: user_mapper.create(user)
NoMethodError:
undefined method `protected_attributes' for #Class:0x007fc3b428de10

I followed your basic example:

require "rubygems"
require "minimapper"
require "minimapper/entity"
require "minimapper/mapper"

class User
include Minimapper::Entity

attributes :name, :email
validates :name, :presence => true
end

class UserMapper < Minimapper::Mapper
class Record < ActiveRecord::Base
self.table_name = "users"
end
end

user = User.new(:name => "Joe")
user_mapper = UserMapper.new
user_mapper.create(user)

Could you give me a light about the error?

Thanks

I haven't tried minimapper with rails 4 yet, but the code you're looking for is probably here: https://github.com/joakimk/minimapper/blob/master/lib/minimapper/mapper.rb#L113

Minimapper tries to avoid assigning to protected attributes because it leads to exceptions in some circumstances: https://github.com/joakimk/minimapper/blob/master/spec/mapper_spec.rb#L139

I think this might be because created_at/updated_at/id is protected by default or something.

Rails 4 removed protected attributes. It's possible that adding them back with https://github.com/rails/protected_attributes works around this issue, but the real fix would be to update Minimapper, which I'm afraid we probably won't have time to do for a while.

Hey guys, I was forgetting to give thanks for help. It worked!