Module: MinimumCrud::Controllers::Base
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/minimum_crud/controllers/base.rb
Instance Method Summary collapse
- #create ⇒ Object
- #destroy ⇒ Object
- #edit ⇒ Object
- #index ⇒ Object
- #new ⇒ Object
- #show ⇒ Object
- #sub_layout_path(action = nil) ⇒ Object
- #update ⇒ Object
Instance Method Details
#create ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/minimum_crud/controllers/base.rb', line 62 def create @record = @model.new(record_params) respond_to do |format| if @record.save format.html { redirect_to ({action: :show, id: @record}), notice: (@record) } if self.enable_json format.json { render :show, status: :created, location: @record } end else format.html { render sub_layout_path(:new) } if self.enable_json format.json { render json: @record.errors, status: :unprocessable_entity } end end end end |
#destroy ⇒ Object
98 99 100 101 102 103 104 105 106 107 |
# File 'lib/minimum_crud/controllers/base.rb', line 98 def destroy @record.destroy respond_to do |format| format.html { redirect_to ({action: :index}), notice: (@record) } if self.enable_json format.json { head :no_content } end end end |
#edit ⇒ Object
58 59 60 |
# File 'lib/minimum_crud/controllers/base.rb', line 58 def edit render sub_layout_path end |
#index ⇒ Object
34 35 36 37 38 39 40 41 42 |
# File 'lib/minimum_crud/controllers/base.rb', line 34 def index @records = @model.all respond_to do |format| format.html { render sub_layout_path } if self.enable_json format.json { } end end end |
#new ⇒ Object
53 54 55 56 |
# File 'lib/minimum_crud/controllers/base.rb', line 53 def new @record = @model.new render sub_layout_path end |
#show ⇒ Object
44 45 46 47 48 49 50 51 |
# File 'lib/minimum_crud/controllers/base.rb', line 44 def show respond_to do |format| format.html { render sub_layout_path } if self.enable_json format.json { } end end end |
#sub_layout_path(action = nil) ⇒ Object
109 110 111 112 113 114 115 116 |
# File 'lib/minimum_crud/controllers/base.rb', line 109 def sub_layout_path(action = nil) action ||= action_name if self.class.sub_layout.try(:to_sym) == :none action else "layouts/minimum_crud/#{self.class.sub_layout}/#{action}" end end |
#update ⇒ Object
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/minimum_crud/controllers/base.rb', line 81 def update respond_to do |format| if @record.update(record_params) format.html { redirect_to ({action: :show, id: @record}), notice: (@record) } if self.enable_json format.json { render :show, status: :ok, location: @record } end else format.html { render sub_layout_path(:edit) } if self.enable_json format.json { render json: @record.errors, status: :unprocessable_entity } end end end end |