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
112 113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/action_crud/controller.rb', line 112 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
140 141 142 143 144 145 146 147 |
# File 'lib/action_crud/controller.rb', line 140 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
104 105 106 107 108 109 |
# File 'lib/action_crud/controller.rb', line 104 def edit respond_to do |format| format.html { render :edit } format.json { render json: record } end end |
#index ⇒ Object
GET /model
75 76 77 78 79 80 81 82 83 |
# File 'lib/action_crud/controller.rb', line 75 def index self.records = model.send index_scope 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
150 151 152 |
# File 'lib/action_crud/controller.rb', line 150 def model record.nil? ? model_class : record.class end |
#new ⇒ Object
GET /model/new
86 87 88 89 90 91 92 93 |
# File 'lib/action_crud/controller.rb', line 86 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
157 158 159 |
# File 'lib/action_crud/controller.rb', line 157 def record instance_variable_get "@#{instance_name}" end |
#records ⇒ Object Also known as: current_records
Get records collection
164 165 166 |
# File 'lib/action_crud/controller.rb', line 164 def records instance_variable_get "@#{collection_name}" end |
#show ⇒ Object
GET /model/1
96 97 98 99 100 101 |
# File 'lib/action_crud/controller.rb', line 96 def show respond_to do |format| format.html { render :show } format.json { render json: record } end end |
#update ⇒ Object
PATCH/PUT /model/1
127 128 129 130 131 132 133 134 135 136 137 |
# File 'lib/action_crud/controller.rb', line 127 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 |