Module: ActionCrud::Controller
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/action_crud/controller.rb
Instance Method Summary collapse
-
#create ⇒ Object
POST /model.
-
#destroy ⇒ Object
DELETE /model/1.
-
#edit ⇒ Object
GET /model/1/edit.
-
#index ⇒ Object
GET /model.
-
#model ⇒ Object
(also: #current_model)
Get model.
-
#new ⇒ Object
GET /model/new.
-
#record ⇒ Object
(also: #current_record)
Get single record.
-
#records ⇒ Object
(also: #current_records)
Get records collection.
-
#show ⇒ Object
GET /model/1.
-
#update ⇒ Object
PATCH/PUT /model/1.
Instance Method Details
#create ⇒ Object
POST /model
124 125 126 127 128 129 130 131 132 133 134 135 136 |
# File 'lib/action_crud/controller.rb', line 124 def create self.record = model.new(record_params) respond_to do |format| if record.save format.html { redirect_to edit_record_path(record), notice: "#{model} was successfully created." } format.json { render json: record, status: :created } else format.html { render :new } format.json { render json: record.errors, status: :unprocessable_entity } end end end |
#destroy ⇒ Object
DELETE /model/1
152 153 154 155 156 157 158 159 |
# File 'lib/action_crud/controller.rb', line 152 def destroy record.destroy respond_to do |format| format.html { redirect_to records_path, notice: "#{model} was successfully destroyed." } format.json { head :no_content } end end |
#edit ⇒ Object
GET /model/1/edit
116 117 118 119 120 121 |
# File 'lib/action_crud/controller.rb', line 116 def edit respond_to do |format| format.html { render :edit } format.json { render json: record } end end |
#index ⇒ Object
GET /model
86 87 88 89 90 91 92 93 94 95 |
# File 'lib/action_crud/controller.rb', line 86 def index self.records = model.send index_scope self.records = model.send(:search, params[:search]) if should_search? self.records = paginate(records) if respond_to? :per_page respond_to do |format| format.html { render :index } format.json { render json: records } end end |
#model ⇒ Object Also known as: current_model
Get model
162 163 164 |
# File 'lib/action_crud/controller.rb', line 162 def model record.nil? ? model_class : record.class end |
#new ⇒ Object
GET /model/new
98 99 100 101 102 103 104 105 |
# File 'lib/action_crud/controller.rb', line 98 def new self.record = model.new respond_to do |format| format.html { render :new } format.json { render json: record } end end |
#record ⇒ Object Also known as: current_record
Get single record
169 170 171 |
# File 'lib/action_crud/controller.rb', line 169 def record instance_variable_get "@#{instance_name}" end |
#records ⇒ Object Also known as: current_records
Get records collection
176 177 178 |
# File 'lib/action_crud/controller.rb', line 176 def records instance_variable_get "@#{collection_name}" end |
#show ⇒ Object
GET /model/1
108 109 110 111 112 113 |
# File 'lib/action_crud/controller.rb', line 108 def show respond_to do |format| format.html { render :show } format.json { render json: record } end end |
#update ⇒ Object
PATCH/PUT /model/1
139 140 141 142 143 144 145 146 147 148 149 |
# File 'lib/action_crud/controller.rb', line 139 def update respond_to do |format| if record.update(record_params) format.html { redirect_to edit_record_path(record), notice: "#{model} was successfully updated." } format.json { render json: record, status: :ok } else format.html { render :edit } format.json { render json: record.errors, status: :unprocessable_entity } end end end |