Class: Plum::Cp::EntriesController
- Inherits:
-
BaseController
- Object
- ApplicationController
- ApplicationController
- BaseController
- Plum::Cp::EntriesController
- Defined in:
- app/controllers/plum/cp/entries_controller.rb
Constant Summary collapse
- ALLOWED_RICH_TEXT_TAGS =
%w[ a action-text-attachment blockquote br code em figcaption figure h1 h2 h3 hr img li ol p pre s strong table tbody td th thead tr ul ].freeze
- ALLOWED_RICH_TEXT_ATTRIBUTES =
%w[ alt caption content-type filename filesize height href presentation rel sgid src target title url width ].freeze
Instance Method Summary collapse
- #create ⇒ Object
- #destroy ⇒ Object
- #edit ⇒ Object
-
#image_field ⇒ Object
Persists one image association without submitting (and potentially overwriting) the other edited fields on the page.
- #index ⇒ Object
- #new ⇒ Object
- #update ⇒ Object
Instance Method Details
#create ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 |
# File 'app/controllers/plum/cp/entries_controller.rb', line 26 def create @entry = @content_type.entries.build(entry_params) @entry.site = current_site @entry. = current_user if current_user.is_a?(Plum::User) if save_entry(@entry) redirect_to edit_cp_content_type_entry_path(@content_type, @entry), notice: "Entry created" else render :new, status: :unprocessable_entity end end |
#destroy ⇒ Object
71 72 73 74 |
# File 'app/controllers/plum/cp/entries_controller.rb', line 71 def destroy @entry.destroy redirect_to cp_content_type_entries_path(@content_type), notice: "Entry deleted" end |
#edit ⇒ Object
38 39 |
# File 'app/controllers/plum/cp/entries_controller.rb', line 38 def edit end |
#image_field ⇒ Object
Persists one image association without submitting (and potentially overwriting) the other edited fields on the page.
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'app/controllers/plum/cp/entries_controller.rb', line 53 def image_field handle = params[:field_handle].to_s field = image_fields.find { |candidate| candidate["handle"].to_s == handle } return render json: { error: "Unknown image field" }, status: :unprocessable_entity unless field asset_id = params[:asset_id].presence if asset_id && !current_site.assets.exists?(id: asset_id) return render json: { error: "Image is not available" }, status: :unprocessable_entity end data = @entry.data.to_h.merge(handle => asset_id&.to_i) if @entry.update(data: data) render json: { saved: true, asset_id: data[handle] } else render json: { error: @entry.errors..to_sentence }, status: :unprocessable_entity end end |
#index ⇒ Object
18 19 20 |
# File 'app/controllers/plum/cp/entries_controller.rb', line 18 def index @entries = @content_type.entries.order(updated_at: :desc) end |
#new ⇒ Object
22 23 24 |
# File 'app/controllers/plum/cp/entries_controller.rb', line 22 def new @entry = @content_type.entries.build(status: :draft, site: current_site) end |
#update ⇒ Object
41 42 43 44 45 46 47 48 49 |
# File 'app/controllers/plum/cp/entries_controller.rb', line 41 def update @entry.assign_attributes(entry_params) if save_entry(@entry) redirect_to edit_cp_content_type_entry_path(@content_type, @entry), notice: "Entry updated" else render :edit, status: :unprocessable_entity end end |