Skip to content

Instantly share code, notes, and snippets.

@mrded
Created October 20, 2013 23:53
Show Gist options
  • Save mrded/7076782 to your computer and use it in GitHub Desktop.
Save mrded/7076782 to your computer and use it in GitHub Desktop.
Rails: Add virtual attribute to model.
class Code < ActiveRecord::Base
attr_accessor :value
def value
'hello'
end
end
class CodesController < ApplicationController
def index
# Code.all.as_json(methods: [:value])
render json: Code.all, methods: [:value]
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment