开发者

How to add values to self.to_json

开发者 https://www.devze.com 2023-03-26 14:38 出处:网络
Right now, if I have a user object like @user. I can do @user.to_json What I want to do is add values to the json object rails creates. I\'ve tried this:

Right now, if I have a user object like @user.

I can do @user.to_json

What I want to do is add values to the json object rails creates. I've tried this:

@user.attributes.merge{ :catalyst_show => true } 

But that errors with syntax error, unexpected tASSOC, expec开发者_JAVA技巧ting '}'

Any ideas on how you can add attributes to the json object?

thanks


you need to add parenthesis. @user.attributes.merge({ :catalyst_show => true }) or @user.attributes.merge( :catalyst_show => true )

0

精彩评论

暂无评论...
验证码 换一张
取 消