Class: Auth::AuthenticatedController

Inherits:
ApplicationController show all
Includes:
Concerns::DeviseConcern, Concerns::TokenConcern
Defined in:
app/controllers/auth/authenticated_controller.rb

Constant Summary collapse

CONDITIONS_FOR_TOKEN_AUTH =
[:create,:update,:destroy,:edit,:new,:index]
TCONDITIONS =
{:only => CONDITIONS_FOR_TOKEN_AUTH}

Instance Method Summary collapse

Methods inherited from ApplicationController

#authenticate_resource!, #build_model_from_params, #check_for_create, #check_for_destroy, #check_for_update, #from_bson, #from_view, #get_model_class_name, #instantiate_classes, #not_found

Instance Method Details

#createObject

POST /auth/assemblies



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'app/controllers/auth/authenticated_controller.rb', line 66

def create

## so how to create an assemly
## there is no difference.

## how to create a stage
## we need to know the assembly version
## and find one and update, where id is that and its version is that.

## we can specify those conditions on the model.
## for example we can have a method called model_create
## and return the model from that.

  respond_to do |format|
      if @model.create_with_conditions(params,@model_params,@model)
          format.json do 
              render json: @model.to_json, status: 201
          end
          format.html do 
              render :show
          end
          format.text do 
              render :text => @model.text_representation 
          end
          format.js do 
              render :partial => "show.js.erb", locals:{model: @model}
          end
      else
       format.json do 
           render json: {
             id: @model.id.to_s,
             errors: @model.errors
           }.to_json, status: 422
       end
       format.html do 
           render :new
       end
       format.js do 
           render :partial => "show.js.erb", locals:{model: @model}
       end
      end
  end
end

#destroyObject

DELETE /auth/assemblies/1



141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
# File 'app/controllers/auth/authenticated_controller.rb', line 141

def destroy
    respond_to do |format|
      if @model.destroy
        format.json do 
          render :nothing => true, :status => 204
        end
        format.js do 
        	render 'destroy'
        end
      else
        format.json do 
          render json: {
            id: @model.id.to_s,
            errors: @model.errors
          }.to_json
        end
        format.js do 
        	render 'destroy'
        end
      end
    end
end

#editObject

GET /auth/assemblies/1/edit



62
63
# File 'app/controllers/auth/authenticated_controller.rb', line 62

def edit
end

#indexObject

GET /auth/assemblies



35
36
37
38
39
40
41
42
43
44
45
# File 'app/controllers/auth/authenticated_controller.rb', line 35

def index
    @models = @model.get_many
    respond_to do |format|
      format.json do 
        render json: @models.to_json
      end
      format.html do 
      	render :index
      end
    end
end

#newObject

GET /auth/assemblies/new



57
58
59
# File 'app/controllers/auth/authenticated_controller.rb', line 57

def new
 	#@auth_assembly = Auth::Assembly.new
end

#onlyObject

add the filters for check_for_create, check_for_update and check_for_destroy



14
# File 'app/controllers/auth/authenticated_controller.rb', line 14

before_action(:only => [:create]){|c| check_for_create(@model)}

#showObject

GET /auth/assemblies/1



48
49
50
51
52
53
54
# File 'app/controllers/auth/authenticated_controller.rb', line 48

def show
    respond_to do |format|
      format.json do 
        render json: @model.to_json
      end
    end
end

#updateObject

PATCH/PUT /auth/assemblies/1



111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
# File 'app/controllers/auth/authenticated_controller.rb', line 111

def update
  respond_to do |format|
    	if @model.update_with_conditions(params,@model_params,@model)
      	format.json do 
        		render :nothing => true, :status => 204
      	end
      	format.js do 
      		render :partial => "show.js.erb", locals: {model: @model}
      	end
      	format.html do 
      		render :show
      	end
    	else
      	format.json do 
        		render json: {
          		id: @model.id.to_s,
          		errors: @model.errors
        		}.to_json, status: 422
      	end
      	format.js do 
      		render :partial => "show.js.erb", locals: {model: @model}
      	end
      	format.html do 
      		render :show
      	end
    	end
  end
end