Module: Tiun::Base

Extended by:
ActiveSupport::Concern
Included in:
CoreController
Defined in:
lib/tiun/base.rb

Defined Under Namespace

Classes: InvalidParamNameError, OutOfRangeError

Instance Method Summary collapse

Instance Method Details

#acObject

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

#createObject

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

#destroyObject

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

#indexObject

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

#showObject

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

#updateObject

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