Skip to content

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

@lnikkila

Description

@lnikkila

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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions