NoMethodError: undefined method `to_msgpack' for #<Subreddit:0x007ff0a3b9b950>

203 views
Skip to first unread message

Esteban Feldman

unread,
Dec 13, 2014, 6:49:01 PM12/13/14
to ohm-...@googlegroups.com
Hi all,

I'm getting this message when I try to create a new Ohm model

Having this 2 models:

class Subreddit < Ohm::Model
attribute :name

index :name

def self.seed(names)
names.each do |name|
create(name: name) if find(name: name).empty?
end
end

def create_entry(attrs)
attrs[:subreddit_id] = id
entry = Entry.create(**attrs)
entry
end
end

class Entry < Ohm::Model
attribute :rid
attribute :title
attribute :url
reference :subreddit, :Subreddit
attribute :permalink

index :rid
index :url
index :subreddit

unique :rid
end




I get this error when I try to use the new_entry on Subreddit on when trying to create an Entry by hand

[1] pry(main)> Subreddit[1]
=> #<Subreddit:0x007fdd0b4f1858 @_memo={}, @attributes={:name=>"pics"}, @id=1>
[2] pry(main)> Entry.create(rid: 1, subreddit_id: 1)
NoMethodError: undefined method `to_msgpack' for #<Subreddit:0x007fdd0b539090>
from /Users/eka/dev/web/sites/rdp-sinatra/vendor/bundle/gems/ohm-2.0.1/lib/ohm.rb:1393:in `to_msgpack'

Any clue on what I'm doing wrong?


Michel Martens

unread,
Dec 13, 2014, 6:59:11 PM12/13/14
to ohm-...@googlegroups.com
Do you have the msgpack gem installed?
> --
>
> ---
> You received this message because you are subscribed to the Google Groups
> "Ohm Ruby" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to ohm-ruby+u...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Michel Martens

unread,
Dec 13, 2014, 7:05:24 PM12/13/14
to ohm-...@googlegroups.com
We discussed this on IRC and it's solved, but for posterity: the error
was in `index :subreddit`, which is not necessary as `reference`
already creates on index on `subreddit_id`.
Reply all
Reply to author
Forward
0 new messages