Created
October 20, 2013 23:53
-
-
Save mrded/7076782 to your computer and use it in GitHub Desktop.
Rails: Add virtual attribute to model.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Code < ActiveRecord::Base | |
attr_accessor :value | |
def value | |
'hello' | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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