Class: Admin::Api::ContentsController

Inherits:
Admin::ApiController
  • Object
show all
Defined in:
app/controllers/admin/api/contents_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



13
14
15
16
17
18
19
20
21
22
23
24
# File 'app/controllers/admin/api/contents_controller.rb', line 13

def create
	@content = Odania::Content.new(content_params)
	@content.user_id = current_user.id
	@content.site_id = @site.id

	if @content.save
		flash[:notice] = t('created')
		render action: :show
	else
		render json: {errors: @content.errors}, status: :bad_request
	end
end

#destroyObject



35
36
37
38
39
40
# File 'app/controllers/admin/api/contents_controller.rb', line 35

def destroy
	@content.destroy

	flash[:notice] = t('deleted')
	render json: {message: 'deleted'}
end

#indexObject



5
6
7
# File 'app/controllers/admin/api/contents_controller.rb', line 5

def index
	@contents = Odania::Content.where(site_id: params[:site_id], language_id: @menu.language_id).order('created_at DESC')
end

#showObject



9
10
11
# File 'app/controllers/admin/api/contents_controller.rb', line 9

def show
	@widgets = Odania::Widget.where(site_id: @site.id)
end

#updateObject



26
27
28
29
30
31
32
33
# File 'app/controllers/admin/api/contents_controller.rb', line 26

def update
	if @content.update(content_params)
		flash[:notice] = t('updated')
		render action: :show
	else
		render json: {errors: @content.errors}, status: :bad_request
	end
end