Class: TagsController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- TagsController
- Defined in:
- app/controllers/tags_controller.rb
Instance Method Summary collapse
-
#destroy ⇒ Object
DELETE /tags/1 DELETE /tags/1.json.
- #edit ⇒ Object
- #index ⇒ Object
- #show ⇒ Object
- #update ⇒ Object
Instance Method Details
#destroy ⇒ Object
DELETE /tags/1 DELETE /tags/1.json
62 63 64 65 66 67 68 69 70 |
# File 'app/controllers/tags_controller.rb', line 62 def destroy # @tag = Tag.find(params[:id]) @tag.destroy respond_to do |format| format.html { redirect_to } format.json { head :no_content } end end |
#edit ⇒ Object
42 43 44 |
# File 'app/controllers/tags_controller.rb', line 42 def edit # @tag = Tag.find(params[:id]) end |
#index ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'app/controllers/tags_controller.rb', line 5 def index session[:params] ={} unless session[:params] session[:params][:tag] = params sort = {sort_by: 'created_at', order: 'desc'} case params[:sort_by] when 'name' sort[:sort_by] = 'name' when 'taggings_count' sort[:sort_by] = 'taggings_count' end sort[:order] = 'asc' if params[:order] == 'asc' query = @query = params[:query].to_s.strip page = params[:page] || 1 @tags = Tag.search do fulltext query if query.present? paginate page: page.to_i, per_page: Tag.default_per_page order_by sort[:sort_by], sort[:order] end.results respond_to do |format| format.html # index.html.erb format.json { render json: @tags } format.rss format.atom end end |
#show ⇒ Object
35 36 37 38 39 40 |
# File 'app/controllers/tags_controller.rb', line 35 def show respond_to do |format| format.html # show.html.erb format.json { render json: @tag } end end |
#update ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'app/controllers/tags_controller.rb', line 46 def update # @tag = Tag.find(params[:id]) respond_to do |format| if @tag.update_attributes(tag_params) format.html { redirect_to @tag, notice: t('controller.successfully_updated', model: t('activerecord.models.tag')) } format.json { head :no_content } else format.html { render action: "edit" } format.json { render json: @tag.errors, status: :unprocessable_entity } end end end |