2015-08-21 01:43:12 +08:00
|
|
|
require_dependency 'embedding'
|
|
|
|
|
2015-08-19 05:15:46 +08:00
|
|
|
class Admin::EmbeddingController < Admin::AdminController
|
|
|
|
|
2018-02-01 09:26:45 +08:00
|
|
|
before_action :fetch_embedding
|
2015-08-19 05:15:46 +08:00
|
|
|
|
|
|
|
def show
|
|
|
|
render_serialized(@embedding, EmbeddingSerializer, root: 'embedding', rest_serializer: true)
|
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
2015-10-14 04:33:26 +08:00
|
|
|
if params[:embedding][:embed_by_username].blank?
|
|
|
|
return render_json_error(I18n.t('site_settings.embed_username_required'))
|
|
|
|
end
|
|
|
|
|
2015-08-21 01:43:12 +08:00
|
|
|
Embedding.settings.each do |s|
|
|
|
|
@embedding.send("#{s}=", params[:embedding][s])
|
|
|
|
end
|
|
|
|
|
|
|
|
if @embedding.save
|
|
|
|
fetch_embedding
|
|
|
|
render_serialized(@embedding, EmbeddingSerializer, root: 'embedding', rest_serializer: true)
|
|
|
|
else
|
|
|
|
render_json_error(@embedding)
|
|
|
|
end
|
2015-08-19 05:15:46 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
protected
|
|
|
|
|
2018-06-07 13:28:18 +08:00
|
|
|
def fetch_embedding
|
|
|
|
@embedding = Embedding.find
|
|
|
|
end
|
2015-08-19 05:15:46 +08:00
|
|
|
end
|