On Apr 4, 3:37 pm, Henry Flower <[email protected]> wrote:
> One more question. If I try to serialize the result into a json, it gives me
> an error:
>
>   NoMethodError: undefined method `votes_up' for #<Checklist:0x292ef508>
>
> apparently because the dynamic column 'votes_up' wasn't predefined in
> 'checklists' table. Is it possible somehow to provide such info to json
> serializer plugin?

You need to define that method in your class:

  def votes_up
    self[:votes_up]
  end

Or you have to use to_json(:except=>:votes_up) to not include the
column in the JSON output.

It's fairly trivial to modify the json_serializer plugin to just use
the value in the values hash if it doesn't respond to the method.  I'm
not sure that's a good idea, though.  For stuff like this, it's often
easier to use plain hashes instead of model objects.

Jeremy

-- 
You received this message because you are subscribed to the Google Groups 
"sequel-talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/sequel-talk?hl=en.

Reply via email to