Module: Tiun::Base
Defined Under Namespace
Classes: InvalidParamNameError, OutOfRangeError
Instance Method Summary collapse
-
#ac ⇒ Object
GET /<objects>/ac.json.
-
#create ⇒ Object
POST /<objects>.json.
-
#destroy ⇒ Object
DELETE /<objects>/:id.json.
-
#index ⇒ Object
GET /<objects>/.
-
#show ⇒ Object
GET /<objects>/:id.json.
-
#update ⇒ Object
PUT /<objects>/:id.json.
Instance Method Details
#ac ⇒ Object
GET /<objects>/ac.json
114 115 116 117 118 119 120 121 122 123 |
# File 'lib/tiun/base.rb', line 114 def ac respond_to do |format| format.json { render json: { list: objects.limit(ac_limit).jsonize(ac_context), total: objects.total_count } } end end |
#create ⇒ Object
POST /<objects>.json
65 66 67 68 69 70 71 72 73 74 |
# File 'lib/tiun/base.rb', line 65 def create object.save! respond_to do |format| format.html format.json { render json: serialize(object) } format.jsonp { head :ok } format.any { render json: serialize(object), content_type: 'application/json' } end end |
#destroy ⇒ Object
DELETE /<objects>/:id.json
99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/tiun/base.rb', line 99 def destroy answer = serialize(object) object.destroy respond_to do |format| format.html format.json { render json: answer } format.jsonp { head :ok } format.any { render json: answer, content_type: 'application/json' } end rescue Exception binding.pry end |
#index ⇒ Object
GET /<objects>/
55 56 57 58 59 60 61 62 |
# File 'lib/tiun/base.rb', line 55 def index respond_to do |format| format.html { render :index } format.json { render status: code, json: serialize_collection(paged_objects) } format.jsonp { render status: code, json: serialize_collection(paged_objects) } format.any { render status: code, json: serialize_collection(paged_objects), content_type: 'application/json' } end end |
#show ⇒ Object
GET /<objects>/:id.json
89 90 91 92 93 94 95 96 |
# File 'lib/tiun/base.rb', line 89 def show respond_to do |format| format.html format.json { render json: serialize(object) } format.jsonp { render json: serialize(object) } format.any { render json: serialize(object), content_type: 'application/json' } end end |
#update ⇒ Object
PUT /<objects>/:id.json
77 78 79 80 81 82 83 84 85 86 |
# File 'lib/tiun/base.rb', line 77 def update object.update!(permitted_params) respond_to do |format| format.html format.json { render json: serialize(object) } format.jsonp { head :ok } format.any { render json: serialize(object), content_type: 'application/json' } end end |