solnic / virtus

[DISCONTINUED ] Attributes on Steroids for Plain Old Ruby Objects
MIT License
3.77k stars 229 forks source link

Is the `mass_assignment: false` example in the README out of date? #325

Closed lnikkila closed 9 years ago

lnikkila commented 9 years ago

Here’s the relevant part:

# include attribute DSL + constructor
class User
  include Virtus.model(:mass_assignment => false)

  attribute :name, String
end

User.new(:name => 'Piotr')

I’m running 1.0.5 and for me this results in a NoMethodError:

NoMethodError: undefined method `allowed_writer_methods' for User:Class
from /Users/lnikkila/.rbenv/versions/2.2.1/lib/ruby/gems/2.2.0/gems/virtus-1.0.5/lib/virtus/class_inclusions.rb:32:in `allowed_writer_methods'

User.new works fine. Is the other initializer still supported?

I’d really like to use it since I want an attribute called attributes (#206) and I don’t really care about mass assignment otherwise.

Looks like the error was introduced by a385ca2. If I do

User.extend(Virtus::Extensions::AllowedWriterMethods)

it works as expected, except for setting the attributes attribute in the initializer. Currently I’m using it as a workaround.

Thanks!

solnic commented 9 years ago

Thanks for reporting this. Looks like a bug :/

novikserg commented 9 years ago

@solnic I would like to solve it if you didn't get started on it yet?