Module: ServiceCrud
- Defined in:
- lib/service_crud/default_orm.rb,
lib/service_crud/service_crud.rb,
lib/service_crud/couchrest_model.rb
Defined Under Namespace
Modules: ClassMethods, CouchRest Classes: DefaultOrm
Class Method Summary collapse
Instance Method Summary collapse
-
#create ⇒ Object
POST /your_model.xml POST /your_model.json.
-
#destroy ⇒ Object
DELETE /your_model/1.xml DELETE /your_model/1.json.
-
#index ⇒ Object
GET /your_model.xml GET /your_model.json.
-
#show ⇒ Object
GET /your_model/1.xml GET /your_model/1.json.
-
#update ⇒ Object
PUT /your_model/1.xml PUT /your_model/1.json.
Class Method Details
.included(base) ⇒ Object
3 4 5 |
# File 'lib/service_crud/service_crud.rb', line 3 def self.included(base) base.extend ClassMethods end |
Instance Method Details
#create ⇒ Object
POST /your_model.xml POST /your_model.json
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/service_crud/service_crud.rb', line 95 def create @model = self.class.model.send self.class.orm_methods.new, params[self.class.model_attribute_root] run_service_crud_before_callbacks @model respond_to do |format| if @model.send self.class.orm_methods.save run_service_crud_after_callbacks @model location = "/#{controller_name}/#{CGI.escape(@model.id)}" format.xml { render :xml => @model, :status => :created, :location => location } format.json { render :json => @model, :status => :created, :location => location } else format.xml { render :xml => @model.errors, :status => :unprocessable_entity } format.json { render :json => {:errors => @model.errors.to_a}.to_json, :status => :unprocessable_entity } end end end |
#destroy ⇒ Object
DELETE /your_model/1.xml DELETE /your_model/1.json
132 133 134 135 136 137 138 139 140 141 142 |
# File 'lib/service_crud/service_crud.rb', line 132 def destroy @model = self.class.model.send self.class.orm_methods.find, params[:id] run_service_crud_before_callbacks @model @model.send self.class.orm_methods.destroy run_service_crud_after_callbacks @model respond_to do |format| format.xml { head :ok } format.json { head :ok } end end |
#index ⇒ Object
GET /your_model.xml GET /your_model.json
67 68 69 70 71 72 73 74 |
# File 'lib/service_crud/service_crud.rb', line 67 def index @models = self.class.model.send self.class.orm_methods.all respond_to do |format| format.xml { render :xml => @models } format.json { render :json => @models } end end |
#show ⇒ Object
GET /your_model/1.xml GET /your_model/1.json
78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/service_crud/service_crud.rb', line 78 def show @model = self.class.model.send self.class.orm_methods.find, params[:id] respond_to do |format| format.xml do render :status => 404, :text => "" and return unless @model render :xml => @model end format.json do render :status => 404, :text => "" and return unless @model render :json => @model end end end |
#update ⇒ Object
PUT /your_model/1.xml PUT /your_model/1.json
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
# File 'lib/service_crud/service_crud.rb', line 114 def update @model = self.class.model.send self.class.orm_methods.find, CGI.unescape(params[:id]) run_service_crud_before_callbacks @model respond_to do |format| if @model.send self.class.orm_methods.update_attributes, params[self.class.model_attribute_root] run_service_crud_after_callbacks @model format.xml { head :ok } format.json { head :ok } else format.xml { render :xml => @model.errors, :status => :unprocessable_entity } format.json { render :json => {:errors => @model.errors.to_a}.to_json, :status => :unprocessable_entity } end end end |