adds create and destroy to the tags CRUD
This commit is contained in:
@@ -1,22 +1,37 @@
|
||||
class Admin::TagsController < Admin::BaseController
|
||||
layout 'admin'
|
||||
before_action :find_tag, only: [:update, :destroy]
|
||||
|
||||
respond_to :html, :js
|
||||
|
||||
def index
|
||||
@tags = ActsAsTaggableOn::Tag.order(featured: :desc)
|
||||
@tag = ActsAsTaggableOn::Tag.new
|
||||
end
|
||||
|
||||
def create
|
||||
ActsAsTaggableOn::Tag.create(tag_params)
|
||||
redirect_to admin_tags_path
|
||||
end
|
||||
|
||||
def update
|
||||
@tag = ActsAsTaggableOn::Tag.find(params[:id])
|
||||
@tag.update(tag_params)
|
||||
redirect_to admin_tags_path
|
||||
end
|
||||
|
||||
def destroy
|
||||
@tag.destroy
|
||||
redirect_to admin_tags_path
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def tag_params
|
||||
params.require(:tag).permit(:featured)
|
||||
params.require(:tag).permit(:featured, :name)
|
||||
end
|
||||
|
||||
def find_tag
|
||||
@tag = ActsAsTaggableOn::Tag.find(params[:id])
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -1,4 +1,14 @@
|
||||
<div class="left">
|
||||
<h1><%= t("admin.tags.index.add_tag") %></h1>
|
||||
|
||||
<%= form_for(@tag, url: admin_tags_path, as: :tag) do |f| %>
|
||||
<%= f.text_field :name, placeholder: t("admin.tags.name.placeholder") %>
|
||||
<%= f.check_box :featured, label: false %>
|
||||
<%= t("admin.tags.mark_as_featured") %>
|
||||
<%= f.submit(class: "button radius small") %>
|
||||
<% end %>
|
||||
|
||||
|
||||
<h1><%= t("admin.tags.index.title") %></h1>
|
||||
|
||||
<ul>
|
||||
@@ -8,9 +18,11 @@
|
||||
|
||||
<%= form_for(tag, url: admin_tag_path(tag), as: :tag, html: { id: "edit_tag_#{tag.id}"}) do |f| %>
|
||||
<%= f.check_box :featured, label: false, id: "tag_featured_#{tag.id}" %>
|
||||
<%= t("admin.tags.index.mark_as_featured") %>
|
||||
<%= t("admin.tags.mark_as_featured") %>
|
||||
<%= f.submit(class: "button radius tiny") %>
|
||||
<%= link_to t("admin.tags.destroy"), admin_tag_path(tag), method: :delete, class: 'button tiny alert' %>
|
||||
<% end %>
|
||||
|
||||
</li>
|
||||
<% end %>
|
||||
</ul>
|
||||
|
||||
@@ -3,6 +3,7 @@ en:
|
||||
models:
|
||||
comment: Comment
|
||||
debate: Debate
|
||||
tag: Tema
|
||||
user: User
|
||||
vote: Vote
|
||||
attributes:
|
||||
@@ -19,4 +20,4 @@ en:
|
||||
first_name: "First name"
|
||||
last_name: "Last name"
|
||||
nickname: Nickname
|
||||
password: Password
|
||||
password: Password
|
||||
|
||||
@@ -3,6 +3,7 @@ es:
|
||||
models:
|
||||
comment: Comentario
|
||||
debate: Debate
|
||||
tag: Topic
|
||||
user: Usuario
|
||||
vote: Voto
|
||||
attributes:
|
||||
@@ -19,4 +20,4 @@ es:
|
||||
first_name: Nombre
|
||||
last_name: Apellidos
|
||||
nickname: Pseudónimo
|
||||
password: Contraseña
|
||||
password: Contraseña
|
||||
|
||||
@@ -6,4 +6,8 @@ en:
|
||||
tags:
|
||||
index:
|
||||
title: 'Debate topics'
|
||||
mark_as_featured: 'Mark as featured'
|
||||
add_tag: 'Add a new debate topic'
|
||||
mark_as_featured: 'Mark as featured'
|
||||
name:
|
||||
placeholder: 'Write a topic'
|
||||
destroy: Delete Tag
|
||||
|
||||
@@ -6,4 +6,8 @@ es:
|
||||
tags:
|
||||
index:
|
||||
title: 'Temas de debate'
|
||||
mark_as_featured: 'Marcar como destacado'
|
||||
add_tag: 'Añade un nuevo tema de debate'
|
||||
mark_as_featured: 'Marcar como destacado'
|
||||
name:
|
||||
placeholder: 'Escribe el nombre del tema'
|
||||
destroy: Elimina la etiqueta
|
||||
|
||||
@@ -24,7 +24,7 @@ Rails.application.routes.draw do
|
||||
namespace :admin do
|
||||
root to: "dashboard#index"
|
||||
|
||||
resources :tags, only: [:index, :update]
|
||||
resources :tags, only: [:index, :create, :update, :destroy]
|
||||
end
|
||||
|
||||
namespace :moderation do
|
||||
|
||||
@@ -74,14 +74,40 @@ feature 'Admin' do
|
||||
end
|
||||
|
||||
context 'Tags' do
|
||||
scenario 'marking tags as featured / unfeatured' do
|
||||
unfeatured_tag = create :tag, :unfeatured, name: 'Mi barrio'
|
||||
let(:unfeatured_tag) { create :tag, :unfeatured, name: 'Mi barrio' }
|
||||
|
||||
background do
|
||||
login_as(administrator)
|
||||
end
|
||||
|
||||
scenario 'adding a new tag' do
|
||||
visit admin_tags_path
|
||||
|
||||
fill_in 'tag_name', with: 'Papeleras'
|
||||
|
||||
click_on 'Create Tag'
|
||||
|
||||
expect(page).to have_content 'Papeleras'
|
||||
end
|
||||
|
||||
scenario 'deleting tag' do
|
||||
unfeatured_tag
|
||||
|
||||
visit admin_tags_path
|
||||
|
||||
expect(page).to have_content 'Mi barrio'
|
||||
|
||||
click_link 'Delete Tag'
|
||||
|
||||
expect(page).not_to have_content 'Mi barrio'
|
||||
end
|
||||
|
||||
scenario 'marking tags as featured / unfeatured' do
|
||||
expect(unfeatured_tag).not_to be_featured
|
||||
|
||||
visit admin_tags_path
|
||||
|
||||
expect(page).to have_content 'Mi barrio'
|
||||
save_and_open_page
|
||||
|
||||
check "tag_featured_#{unfeatured_tag.id}"
|
||||
click_button 'Update Tag'
|
||||
|
||||
Reference in New Issue
Block a user