Module: ResourceControllerExtensions::JSON::ClassMethods

Defined in:
lib/resource_controller_extensions/json.rb

Instance Method Summary collapse

Instance Method Details

#init_default_actions_with_json(klass) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/resource_controller_extensions/json.rb', line 13

def init_default_actions_with_json(klass)
  init_default_actions_without_json(klass)
  klass.class_eval do
    index.wants.json { render :json => collection.to_json, :status => :ok }
    show.wants.json { render :json => object}
    edit.wants.json { render :json => object}

    create.wants.json { render :json => object, :status => :created, :location => object_url }
    create.failure.wants.json { render :json => {:errors => object.errors.full_messages}, :status => :unprocessable_entity }
    destroy.wants.json { head :ok }
    update.wants.json { head :ok }
    update.failure.wants.json { render :json => {:errors => object.errors.full_messages}, :status => :unprocessable_entity }
  end
end