datamapper/dm-core — Issue #159: undefined method `include?' for nil:NilClass in 1.2.0 but not 1.1.0
Author: chriscummings
Created: 2011-10-27 05:42:50+00:00
State: open

I'm using DataMapper with Sinatra and I've found that I keep getting the following error with DataMapper 1.2.0:

```
NoMethodError at /tag
undefined method `include?' for nil:NilClass

file: resource.rb
location: block in attributes=
line: 332
```

__Backtrace__

```
/Users/chris/Desktop/chriscummings-Blog-9331485/controllers/tag.rb in new

tag = Tag.new({

/Users/chris/Desktop/chriscummings-Blog-9331485/controllers/tag.rb in block in

tag = Tag.new({

/Users/chris/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/webrick/httpserver.rb in service

si.service(req, res)

/Users/chris/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/webrick/httpserver.rb in run

server.service(req, res)

/Users/chris/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/webrick/server.rb in block in start_thread

block ? block.call(sock) : run(sock)
```

There's nothing wrong with the file mentioned `controllers/tag.rb`. I get the same error with any path that tries to create/update/delete a record. If I force `gem 'data_mapper', '= 1.1.0'` in my `Gemfile` I don't experience the issue.

__Potentially pertinent code__

***

__controllers/tag.rb__
_Like I said, the error pops up on any path that attempts to edit a record. Additionally, the ` require_administrative_privileges` and `tag_validate!` methods don't do anything magical and commenting them out makes no difference._

```ruby
post '/tag/?' do
require_administrative_privileges
tag_validate!(params)

#Ensure uniques
tag = Tag.first(:name => params[:name])
if tag
halt 409, "Tag \"" + tag.name + "\" already exists!"
end

tag = Tag.new({
:name => params[:name],
:created_at => Time.now
})

if tag.save
status(201)
redirect '/tag'
else
halt 409, tag.errors.inspect
end
end
```

__My DataMapper models file__

```ruby
class Post
include DataMapper::Resource

property :id, Serial
property :created_at, DateTime
property :updated_at, DateTime
property :title, Text
property :body, Text
property :body_md, Text
property :slug, Text

has n, :posttags
has n, :tags, :through => :posttags
end

class Tag
include DataMapper::Resource

property :id, Serial
property :created_at, DateTime
property :updated_at, DateTime
property :name, Text

has n, :posttags
has n, :posts, :through => :posttags
end

class Posttag
include DataMapper::Resource

property :id, Serial

belongs_to :tag, :key => true
belongs_to :post, :key => true
end

class Page
include DataMapper::Resource

property :id, Serial
property :created_at, DateTime
property :updated_at, DateTime
property :title, Text
property :body, Text
property :body_md, Text
property :slug, Text
end
```