Module: Plutonium::Resource::Controllers::CrudActions
- Extended by:
- ActiveSupport::Concern
- Includes:
- IndexAction
- Included in:
- Plutonium::Resource::Controller
- Defined in:
- lib/plutonium/resource/controllers/crud_actions.rb,
lib/plutonium/resource/controllers/crud_actions/index_action.rb
Defined Under Namespace
Modules: IndexAction
Instance Method Summary collapse
-
#create ⇒ Object
POST /resources(.format).
-
#destroy ⇒ Object
DELETE /resources/1(.format).
-
#edit ⇒ Object
GET /resources/1/edit.
-
#index ⇒ Object
GET /resources(.format).
-
#new ⇒ Object
GET /resources/new.
-
#show ⇒ Object
GET /resources/1(.format).
-
#update ⇒ Object
PATCH/PUT /resources/1(.format).
Instance Method Details
#create ⇒ Object
POST /resources(.format)
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/plutonium/resource/controllers/crud_actions.rb', line 42 def create resource_class set_page_title "Create #{resource_class.model_name.human.titleize}" @resource_record = resource_class.new resource_params respond_to do |format| if params[:pre_submit] format.html { render :new, status: :unprocessable_content } elsif resource_record!.save format.html do redirect_to redirect_url_after_submit, notice: "#{resource_class.model_name.human} was successfully created." end format.any do render :show, status: :created, location: redirect_url_after_submit end else format.html { render :new, status: :unprocessable_content } format.any do @errors = resource_record!.errors render "errors", status: :unprocessable_content end end end end |
#destroy ⇒ Object
DELETE /resources/1(.format)
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 |
# File 'lib/plutonium/resource/controllers/crud_actions.rb', line 112 def destroy resource_record! respond_to do |format| resource_record!.destroy format.html do redirect_to redirect_url_after_destroy, notice: "#{resource_class.model_name.human} was successfully deleted." end format.json { head :no_content } rescue ActiveRecord::InvalidForeignKey format.html do redirect_to resource_url_for(resource_record!), alert: "#{resource_class.model_name.human} is referenced by other records." end format.any do @errors = ActiveModel::Errors.new resource_record! @errors.add :base, :existing_references, message: "is referenced by other records" render "errors", status: :unprocessable_content end end end |
#edit ⇒ Object
GET /resources/1/edit
72 73 74 75 76 77 78 79 |
# File 'lib/plutonium/resource/controllers/crud_actions.rb', line 72 def edit resource_record! set_page_title "Update #{resource_record!.to_label.titleize}" maybe_apply_submitted_resource_params! render :edit end |
#index ⇒ Object
GET /resources(.format)
13 14 15 16 17 18 19 20 |
# File 'lib/plutonium/resource/controllers/crud_actions.rb', line 13 def index resource_class set_page_title resource_class.model_name.human.pluralize.titleize setup_index_action! render :index end |
#new ⇒ Object
GET /resources/new
31 32 33 34 35 36 37 38 39 |
# File 'lib/plutonium/resource/controllers/crud_actions.rb', line 31 def new resource_class set_page_title "Create #{resource_class.model_name.human.titleize}" @resource_record = resource_class.new maybe_apply_submitted_resource_params! render :new end |
#show ⇒ Object
GET /resources/1(.format)
23 24 25 26 27 28 |
# File 'lib/plutonium/resource/controllers/crud_actions.rb', line 23 def show resource_record! set_page_title resource_record!.to_label.titleize render :show end |
#update ⇒ Object
PATCH/PUT /resources/1(.format)
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/plutonium/resource/controllers/crud_actions.rb', line 82 def update resource_record! set_page_title "Update #{resource_record!.to_label.titleize}" resource_record!.attributes = resource_params respond_to do |format| if params[:pre_submit] format.html { render :edit, status: :unprocessable_content } elsif resource_record!.save format.html do redirect_to redirect_url_after_submit, notice: "#{resource_class.model_name.human} was successfully updated.", status: :see_other end format.any do render :show, status: :ok, location: redirect_url_after_submit end else format.html { render :edit, status: :unprocessable_content } format.any do @errors = resource_record!.errors render "errors", status: :unprocessable_content end end end end |