Class: OpenObjectsController

Inherits:
ActionController::Base
  • Object
show all
Defined in:
lib/app/controllers/open_objects_controller.rb

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Class Attribute Details

.model_classObject

Returns the value of attribute model_class.



12
13
14
# File 'lib/app/controllers/open_objects_controller.rb', line 12

def model_class
  @model_class
end

Class Method Details

.ids_from_param(param) ⇒ Object



26
27
28
29
30
31
32
# File 'lib/app/controllers/open_objects_controller.rb', line 26

def ids_from_param(param)
  if param.split(',').size > 0
    return eval param
  else
    return param
  end
end

Instance Method Details

#createObject

POST /models POST /models.xml



80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/app/controllers/open_objects_controller.rb', line 80

def create
  @models = self.class.model_class.new(params[:partners])

  respond_to do |format|
    if @models.save
      flash[:notice] = 'Model was successfully created.'
      format.html { redirect_to(@models) }
      format.xml  { render :xml => @models, :status => :created, :location => @models }
    else
      format.html { render :action => "new" }
      format.xml  { render :xml => @models.errors, :status => :unprocessable_entity }
    end
  end
end

#destroyObject

DELETE /models/1 DELETE /models/1.xml



114
115
116
117
118
119
120
121
122
# File 'lib/app/controllers/open_objects_controller.rb', line 114

def destroy
  @models = self.class.model_class.find(params[:id])
  @models.destroy

  respond_to do |format|
    format.html { redirect_to(url_for(:action => index)) }
    format.xml  { head :ok }
  end
end

#editObject

GET /models/1/edit



74
75
76
# File 'lib/app/controllers/open_objects_controller.rb', line 74

def edit
  @models = self.class.model_class.find(params[:id])
end

#indexObject

GET /models GET /models.xml



41
42
43
44
45
46
47
48
# File 'lib/app/controllers/open_objects_controller.rb', line 41

def index
  @models = self.class.model_class.find(:all)

  respond_to do |format|
    format.html # index.html.erb
    format.xml  { render :xml => @models }
  end
end

#newObject

GET /models/new GET /models/new.xml



64
65
66
67
68
69
70
71
# File 'lib/app/controllers/open_objects_controller.rb', line 64

def new
  @models = self.class.model_class.new

  respond_to do |format|
    format.html # new.html.erb
    format.xml  { render :xml => @models }
  end
end

#showObject

GET /models/1 GET /models/1.xml



52
53
54
55
56
57
58
59
60
# File 'lib/app/controllers/open_objects_controller.rb', line 52

def show
  @models = self.class.model_class.find(self.class.ids_from_param(params[:id]))

  respond_to do |format|
    format.html # show.html.erb
    format.xml  { render :xml => @models }
    format.json  { render :json => @models }
  end
end

#updateObject

PUT /models/1 PUT /models/1.xml



97
98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/app/controllers/open_objects_controller.rb', line 97

def update
  @models = self.class.model_class.find(params[:id])

  respond_to do |format|
    if @models.update_attributes(params[:partners])
      flash[:notice] = 'Partners was successfully updated.'
      format.html { redirect_to(@models) }
      format.xml  { head :ok }
    else
      format.html { render :action => "edit" }
      format.xml  { render :xml => @models.errors, :status => :unprocessable_entity }
    end
  end
end