Rails model as_json overwriting default values -
I am trying to overwrite default model values for JSON, but instead of overwriting it is a duplicate hash < / P>
My model:
class home screen button & lt; ActiveRecord :: Base is_to: product_category Valid: product_category_id ,: x ,: y ,: presence = & gt; Correct attr_accessible: product_category_id, x, y def as_json (option = {}) hash = super (option) hash. Merge ({: product_category_id => "fdfd"}) end < P> My Controller: DIF Index @home_screen_buttons = HomeScreenButton.all response_to do | Format | Format.html # index.html.erb format.json {json: @home_screen_buttons} End End When I open Jason, I show a duplicate for product_category_id: [[ "Created_at": "2013-03-17T11: 14: 32Z", "id": 1, "product_category_id": 5, "updated_at": "2013-03-17T11: 14: 32Z", "X": 300, "Y": 200, "product_category_id": "dfdffff"}]
there Hash = [fdfd] hash and
Comments
Post a Comment