From 0a4aafd8ded6d5eb314456310c517aa2bd511fad Mon Sep 17 00:00:00 2001 From: David Gil Date: Sat, 15 Aug 2015 18:22:29 +0200 Subject: [PATCH] scaffolds a tag list to mark tags as featured on the admin section --- app/controllers/admin/tags_controller.rb | 22 ++++++++++++++++++++++ app/views/admin/_menu.html.erb | 4 ++-- app/views/admin/tags/index.html.erb | 18 ++++++++++++++++++ config/locales/en.yml | 7 +++++++ config/locales/es.yml | 7 +++++++ config/routes.rb | 2 ++ db/schema.rb | 3 ++- 7 files changed, 60 insertions(+), 3 deletions(-) create mode 100644 app/controllers/admin/tags_controller.rb create mode 100644 app/views/admin/tags/index.html.erb diff --git a/app/controllers/admin/tags_controller.rb b/app/controllers/admin/tags_controller.rb new file mode 100644 index 000000000..61df7968e --- /dev/null +++ b/app/controllers/admin/tags_controller.rb @@ -0,0 +1,22 @@ +class Admin::TagsController < Admin::BaseController + layout 'admin' + + respond_to :html, :js + + def index + @tags = ActsAsTaggableOn::Tag.order(featured: :desc) + end + + def update + @tag = ActsAsTaggableOn::Tag.find(params[:id]) + @tag.update(tag_params) + redirect_to admin_tags_path + end + + private + + def tag_params + params.require(:tag).permit(:featured) + end + +end diff --git a/app/views/admin/_menu.html.erb b/app/views/admin/_menu.html.erb index 82c747f2b..79540a5d0 100644 --- a/app/views/admin/_menu.html.erb +++ b/app/views/admin/_menu.html.erb @@ -1,3 +1,3 @@
- Admin links -
\ No newline at end of file + <%= link_to t('admin.tags.index.title'), admin_tags_path %> + diff --git a/app/views/admin/tags/index.html.erb b/app/views/admin/tags/index.html.erb new file mode 100644 index 000000000..cc0375749 --- /dev/null +++ b/app/views/admin/tags/index.html.erb @@ -0,0 +1,18 @@ +
+

<%= t("admin.tags.index.title") %>

+ + +
diff --git a/config/locales/en.yml b/config/locales/en.yml index b5d2bccf2..cf9126cd0 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -78,6 +78,8 @@ en: comment_button: Publish comment reply_link: Reply reply_button: Publish reply + tags: + featured: Featured votes: agree: I agree disagree: I disagree @@ -117,3 +119,8 @@ en: default: "You are not authorized to access this page." manage: all: "You are not authorized to %{action} %{subject}." + admin: + tags: + index: + title: 'Debate topics' + mark_as_featured: 'Mark as featured' diff --git a/config/locales/es.yml b/config/locales/es.yml index 6a4cacf53..0ca1fe2d9 100644 --- a/config/locales/es.yml +++ b/config/locales/es.yml @@ -78,6 +78,8 @@ es: comment_button: Publicar comentario reply_link: Responder reply_button: Publicar respuesta + tags: + featured: Destacado votes: agree: Estoy de acuerdo disagree: No estoy de acuerdo @@ -129,3 +131,8 @@ es: all: "No tienes permiso para borrar %{subject}" manage: all: "No tienes permiso para realizar la acción '%{action}' sobre %{subject}." + admin: + tags: + index: + title: 'Temas de debate' + mark_as_featured: 'Marcar como destacado' diff --git a/config/routes.rb b/config/routes.rb index fc7c040b2..a0b9a97d9 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -23,6 +23,8 @@ Rails.application.routes.draw do namespace :admin do root to: "dashboard#index" + + resources :tags, only: [:index, :update] end namespace :moderation do diff --git a/db/schema.rb b/db/schema.rb index 8fb58776c..4e8e2c286 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20150811161459) do +ActiveRecord::Schema.define(version: 20150815154430) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -79,6 +79,7 @@ ActiveRecord::Schema.define(version: 20150811161459) do create_table "tags", force: :cascade do |t| t.string "name" t.integer "taggings_count", default: 0 + t.boolean "featured", default: false end add_index "tags", ["name"], name: "index_tags_on_name", unique: true, using: :btree