undefined method `serializable_hash' for String
Asked Answered
F

1

18

i'm trying to_json in the following way

 @own_events.as_json(:include => {:created_date => {},:attendees => {}, :user => {}, :start_times => {}, :end_times =>{}} )

and created_date is a method like that

def created_date
  self.created_at.strftime('%d/%m/%Y %H:%M:%S')
end

cause i need the created_at without the TZD .. but there is an error

NoMethodError (undefined method `serializable_hash' for "14/04/2014 16:04:07":String):

Fyke answered 17/4, 2014 at 15:4 Comment(0)
D
60

:include is used to include associations in the json, usually has_many or belongs_to associations.

To include methods like created_date, use methods:

Such as:

@own_events.as_json(include: [:attendees, :user, :start_times, :end_times], methods: :created_date )
Downhaul answered 17/4, 2014 at 15:24 Comment(1)
SO should allow you to upvote again if it's been over a year since you last saw the answer and you found it useful again hahaBroncobuster

© 2022 - 2024 — McMap. All rights reserved.