Module: Godmin::Resource
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/godmin/resource.rb,
lib/godmin/resource/scopes.rb,
lib/godmin/resource/filters.rb,
lib/godmin/resource/ordering.rb,
lib/godmin/resource/pagination.rb,
lib/godmin/resource/batch_actions.rb
Defined Under Namespace
Modules: BatchActions, Filters, Ordering, Pagination, Scopes
Instance Method Summary
collapse
Instance Method Details
Gives the view access to the list of attributes to be included in the default form
124
125
126
|
# File 'lib/godmin/resource.rb', line 124
def attrs_for_form
[]
end
|
#attrs_for_index ⇒ Object
Gives the view access to the list of column names to be printed in the index view
118
119
120
|
# File 'lib/godmin/resource.rb', line 118
def attrs_for_index
[]
end
|
#create ⇒ Object
81
82
83
84
85
86
87
88
89
90
91
92
93
|
# File 'lib/godmin/resource.rb', line 81
def create
@resource = resource_class.new(resource_params)
respond_to do |format|
if @resource.save
format.html { redirect_to redirect_after_create, notice: redirect_flash_message }
format.json { render :show, status: :created, location: @resource }
else
format.html { render :edit }
format.json { render json: @resource.errors, status: :unprocessable_entity }
end
end
end
|
#destroy ⇒ Object
107
108
109
110
111
112
113
114
|
# File 'lib/godmin/resource.rb', line 107
def destroy
@resource.destroy
respond_to do |format|
format.html { redirect_to redirect_after_destroy, notice: redirect_flash_message }
format.json { head :no_content }
end
end
|
#edit ⇒ Object
78
79
|
# File 'lib/godmin/resource.rb', line 78
def edit
end
|
#index ⇒ Object
61
62
63
64
65
66
|
# File 'lib/godmin/resource.rb', line 61
def index
respond_to do |format|
format.html
format.json { render json: @resources.to_json }
end
end
|
#new ⇒ Object
75
76
|
# File 'lib/godmin/resource.rb', line 75
def new
end
|
#resource ⇒ Object
53
54
55
56
57
58
59
|
# File 'lib/godmin/resource.rb', line 53
def resource
if params[:id]
resources_relation.find(params[:id])
else
resources_relation.new
end
end
|
#resource_class ⇒ Object
33
34
35
|
# File 'lib/godmin/resource.rb', line 33
def resource_class
controller_name.classify.constantize
end
|
#resources ⇒ Object
41
42
43
44
45
46
47
48
49
50
51
|
# File 'lib/godmin/resource.rb', line 41
def resources
(
apply_order(
apply_filters(
apply_scope(
resources_relation
)
)
)
)
end
|
#resources_relation ⇒ Object
37
38
39
|
# File 'lib/godmin/resource.rb', line 37
def resources_relation
resource_class.all
end
|
#show ⇒ Object
68
69
70
71
72
73
|
# File 'lib/godmin/resource.rb', line 68
def show
respond_to do |format|
format.html
format.json { render json: @resource.to_json }
end
end
|
#update ⇒ Object
95
96
97
98
99
100
101
102
103
104
105
|
# File 'lib/godmin/resource.rb', line 95
def update
respond_to do |format|
if @resource.update(resource_params)
format.html { redirect_to redirect_after_update, notice: redirect_flash_message }
format.json { render :show, status: :ok, location: @resource }
else
format.html { render :edit }
format.json { render json: @resource.errors, status: :unprocessable_entity }
end
end
end
|