Created
October 22, 2011 23:59
-
-
Save searls/1306652 to your computer and use it in GitHub Desktop.
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 Camel < ActiveRecord::Base | |
def initialize(attributes = nil, options = {}) | |
super(underscore_keys(attributes), options) | |
end | |
def attributes=(new_attributes, guard_protected_attributes=nil) | |
super(underscore_keys(new_attributes, guard_protected_attributes)) | |
end | |
def serializable_hash(options = nil) | |
Hash[super(options).map { |k,v| [k.to_s.camelize.uncapitalize,v] }] | |
end | |
private | |
def underscore_keys(hash) | |
Hash[hash.map { |k,v| [k.to_s.underscore.to_sym,v] }] | |
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 CamelController < ApplicationController | |
respond_to :json | |
def index | |
respond_with Camel.all | |
end | |
def create | |
@camel = Camel.new(params[:camel]) | |
if @camel.save | |
respond_with @camel, status: :created, location: @camel | |
else | |
respond_with @camel.errors, status: :unprocessable_entity | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment