字符串的未定义方法`serializable_hash' [英] undefined method `serializable_hash' for String

查看:35
本文介绍了字符串的未定义方法`serializable_hash'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在以下列方式尝试 to_json

i'm trying to_json in the following way

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

created_date 就是这样的方法

and created_date is a method like that

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

因为我需要没有 TZD 的 created_at .. 但是有一个错误

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

NoMethodError(未定义方法`serializable_hash' for "14/04/2014 16:04:07":String):

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

推荐答案

:include 用于在 json 中包含关联,通常是 has_manybelongs_to 关联.

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

要包含像 created_date 这样的方法,请使用 methods:

To include methods like created_date, use methods:

例如:

@own_events.as_json(include: [:attendees, :user, :start_times, :end_times], methods: :created_date )

这篇关于字符串的未定义方法`serializable_hash'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆