Class: Railspress::Api::V1::TagsController
- Inherits:
-
BaseController
- Object
- ActionController::API
- BaseController
- Railspress::Api::V1::TagsController
- Defined in:
- app/controllers/railspress/api/v1/tags_controller.rb
Instance Attribute Summary
Attributes inherited from BaseController
Instance Method Summary collapse
Instance Method Details
#create ⇒ Object
29 30 31 32 33 34 35 36 37 |
# File 'app/controllers/railspress/api/v1/tags_controller.rb', line 29 def create tag = Railspress::Tag.new(tag_params) if tag.save render json: { data: serialize_tag(tag) }, status: :created else render_validation_errors(tag) end end |
#destroy ⇒ Object
47 48 49 50 |
# File 'app/controllers/railspress/api/v1/tags_controller.rb', line 47 def destroy @tag.destroy head :no_content end |
#index ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'app/controllers/railspress/api/v1/tags_controller.rb', line 9 def index = Railspress::Tag.ordered total_count = .count = .offset((page - 1) * per_page).limit(per_page) render json: { data: .map { |tag| serialize_tag(tag) }, meta: { page: page, per: per_page, total_count: total_count, total_pages: (total_count.to_f / per_page).ceil } } end |
#show ⇒ Object
25 26 27 |
# File 'app/controllers/railspress/api/v1/tags_controller.rb', line 25 def show render json: { data: serialize_tag(@tag) } end |
#update ⇒ Object
39 40 41 42 43 44 45 |
# File 'app/controllers/railspress/api/v1/tags_controller.rb', line 39 def update if @tag.update(tag_params) render json: { data: serialize_tag(@tag) } else render_validation_errors(@tag) end end |