Class: EditableContent::EditablesController

Inherits:
ApplicationController
  • Object
show all
Includes:
Mercury::Authentication
Defined in:
app/controller/editable_content/editables_controller.rb

Instance Method Summary collapse

Methods included from Mercury::Authentication

#can_edit?

Instance Method Details

#updateObject



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'app/controller/editable_content/editables_controller.rb', line 5

def update
	if can_edit?
		params[:content].each do |key, value|
			editable = Editable.find_by_key key
			if value[:type] == "image" and !value[:attributes][:src].start_with?("/assets")
				editable.update_attribute(:src, value[:attributes][:src])
			else
				editable.update_attribute(:text, value[:value])
			end
		end
		render json: {status: "ok"}
	else
		render nothing: true, status: :unauthorized
	end
end