Module: Trestle::Resource::Controller::Actions
- Included in:
- Trestle::ResourceController
- Defined in:
- app/controllers/concerns/trestle/resource/controller/actions.rb
Instance Method Summary collapse
- #create ⇒ Object
- #destroy ⇒ Object
- #edit ⇒ Object
- #index ⇒ Object
- #new ⇒ Object
- #show ⇒ Object
- #update ⇒ Object
Instance Method Details
#create ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'app/controllers/concerns/trestle/resource/controller/actions.rb', line 23 def create if save_instance respond_to do |format| format.html do flash[:message] = ("create.success", title: "Success!", message: "The %{lowercase_model_name} was successfully created.") redirect_to_return_location(:create, instance) { admin.instance_path(instance) } end format.json { render json: instance, status: :created, location: admin.instance_path(instance) } yield format if block_given? end else respond_to do |format| format.html do flash.now[:error] = ("create.failure", title: "Warning!", message: "Please correct the errors below.") render "new", status: :unprocessable_entity end format.json { render json: instance.errors, status: :unprocessable_entity } yield format if block_given? end end end |
#destroy ⇒ Object
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'app/controllers/concerns/trestle/resource/controller/actions.rb', line 107 def destroy success = delete_instance respond_to do |format| format.html do if success flash[:message] = ("destroy.success", title: "Success!", message: "The %{lowercase_model_name} was successfully deleted.") redirect_to_return_location(:destroy, instance) { admin.path(:index) } else flash[:error] = ("destroy.failure", title: "Warning!", message: "Could not delete %{lowercase_model_name}.") if load_instance redirect_to_return_location(:update, instance) { admin.instance_path(instance) } else redirect_to_return_location(:destroy, instance) { admin.path(:index) } end end end format.json { head :no_content } yield format if block_given? end end |
#edit ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'app/controllers/concerns/trestle/resource/controller/actions.rb', line 65 def edit if admin.singular? && instance.nil? respond_to do |format| format.html { redirect_to action: :new } format.json { head :not_found } yield format if block_given? end else respond_to do |format| format.html format.json { render json: instance } yield format if block_given? end end end |
#index ⇒ Object
5 6 7 8 9 10 11 12 |
# File 'app/controllers/concerns/trestle/resource/controller/actions.rb', line 5 def index respond_to do |format| format.html format.json { render json: collection } yield format if block_given? end end |
#new ⇒ Object
14 15 16 17 18 19 20 21 |
# File 'app/controllers/concerns/trestle/resource/controller/actions.rb', line 14 def new respond_to do |format| format.html format.json { render json: instance } yield format if block_given? end end |
#show ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'app/controllers/concerns/trestle/resource/controller/actions.rb', line 47 def show if admin.singular? && instance.nil? respond_to do |format| format.html { redirect_to action: :new } format.json { head :not_found } yield format if block_given? end else respond_to do |format| format.html format.json { render json: instance } yield format if block_given? end end end |
#update ⇒ Object
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'app/controllers/concerns/trestle/resource/controller/actions.rb', line 83 def update if update_instance respond_to do |format| format.html do flash[:message] = ("update.success", title: "Success!", message: "The %{lowercase_model_name} was successfully updated.") redirect_to_return_location(:update, instance) { admin.instance_path(instance) } end format.json { render json: instance, status: :ok } yield format if block_given? end else respond_to do |format| format.html do flash.now[:error] = ("update.failure", title: "Warning!", message: "Please correct the errors below.") render "show", status: :unprocessable_entity end format.json { render json: instance.errors, status: :unprocessable_entity } yield format if block_given? end end end |