1

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, expecting '}'

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

thanks

AnApprentice
  • 108,152
  • 195
  • 629
  • 1,012
  • 1
    See http://stackoverflow.com/questions/6892044 and http://stackoverflow.com/questions/6879589 to start. – mu is too short Aug 05 '11 at 03:02
  • Ruby thinks you're passing a block to `merge`, instead of the `Hash` you intended. So to make it clear to Ruby, you need to disambiguate - see Sameer's answer. – Zabba Aug 05 '11 at 03:19

1 Answers1

5

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

Sameer C
  • 2,777
  • 1
  • 18
  • 12