-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
258 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
class TagsController < ApplicationController | ||
before_action :set_tag, only: [:show, :edit, :update, :destroy] | ||
|
||
def show | ||
@data_sets = DataSet.tagged_with(@tag) | ||
end | ||
|
||
def edit | ||
end | ||
|
||
def update | ||
@tag = ActsAsTaggableOn::Tag.find(params[:id]) | ||
|
||
throw Exception | ||
|
||
respond_to do |format| | ||
if @tag.update(tag_params) | ||
format.html { redirect_to tag_path(@tag), notice: t('Tag was successfully updated.') } | ||
format.json { render :show, status: :ok, location: @tag } | ||
else | ||
format.html { render :edit } | ||
format.json { render json: @tag.errors, status: :unprocessable_entity } | ||
end | ||
end | ||
|
||
end | ||
|
||
private | ||
|
||
def set_tag | ||
@tag = ActsAsTaggableOn::Tag.find(params[:id]) | ||
end | ||
|
||
def tag_params | ||
params.require(:acts_as_taggable_on_tag).permit(:id) | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
.mb-4.card | ||
.card-body | ||
%h5.card-title= link_to data_set.title, data_set | ||
%h6.card-subtitle.mb-2.text-muted | ||
|
||
%p.card-text | ||
%small= strip_tags(data_set.body).truncate(150) | ||
|
||
- data_set.tags.each do |tag| | ||
= link_to tag.name, tag_path(tag), class: "btn btn-outline-secondary btn-sm" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
= simple_form_for @tag, url: tag_path(@tag) do |f| | ||
= f.submit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
.pb-2 | ||
%h2= @tag.name | ||
|
||
= render "form" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
.pb-2 | ||
%h2 | ||
= @tag.name | ||
|
||
%section.py-2 | ||
%h5.text-muted= t('data_sets') | ||
.row | ||
- @data_sets.each do |data_set| | ||
.col-6 | ||
= render data_set |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
devise_for :users | ||
|
||
resources :data_sets | ||
resources :tags | ||
|
||
root "data_sets#index" | ||
end |
37 changes: 37 additions & 0 deletions
37
db/migrate/20200214025007_acts_as_taggable_on_migration.acts_as_taggable_on_engine.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# This migration comes from acts_as_taggable_on_engine (originally 1) | ||
if ActiveRecord.gem_version >= Gem::Version.new('5.0') | ||
class ActsAsTaggableOnMigration < ActiveRecord::Migration[4.2]; end | ||
else | ||
class ActsAsTaggableOnMigration < ActiveRecord::Migration; end | ||
end | ||
ActsAsTaggableOnMigration.class_eval do | ||
def self.up | ||
create_table ActsAsTaggableOn.tags_table do |t| | ||
t.string :name | ||
t.timestamps | ||
end | ||
|
||
create_table ActsAsTaggableOn.taggings_table do |t| | ||
t.references :tag, foreign_key: { to_table: ActsAsTaggableOn.tags_table } | ||
|
||
# You should make sure that the column created is | ||
# long enough to store the required class names. | ||
t.references :taggable, polymorphic: true | ||
t.references :tagger, polymorphic: true | ||
|
||
# Limit is created to prevent MySQL error on index | ||
# length for MyISAM table type: http://bit.ly/vgW2Ql | ||
t.string :context, limit: 128 | ||
|
||
t.datetime :created_at | ||
end | ||
|
||
add_index ActsAsTaggableOn.taggings_table, :tag_id | ||
add_index ActsAsTaggableOn.taggings_table, [:taggable_id, :taggable_type, :context], name: 'taggings_taggable_context_idx' | ||
end | ||
|
||
def self.down | ||
drop_table ActsAsTaggableOn.taggings_table | ||
drop_table ActsAsTaggableOn.tags_table | ||
end | ||
end |
26 changes: 26 additions & 0 deletions
26
db/migrate/20200214025008_add_missing_unique_indices.acts_as_taggable_on_engine.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# This migration comes from acts_as_taggable_on_engine (originally 2) | ||
if ActiveRecord.gem_version >= Gem::Version.new('5.0') | ||
class AddMissingUniqueIndices < ActiveRecord::Migration[4.2]; end | ||
else | ||
class AddMissingUniqueIndices < ActiveRecord::Migration; end | ||
end | ||
AddMissingUniqueIndices.class_eval do | ||
def self.up | ||
add_index ActsAsTaggableOn.tags_table, :name, unique: true | ||
|
||
remove_index ActsAsTaggableOn.taggings_table, :tag_id if index_exists?(ActsAsTaggableOn.taggings_table, :tag_id) | ||
remove_index ActsAsTaggableOn.taggings_table, name: 'taggings_taggable_context_idx' | ||
add_index ActsAsTaggableOn.taggings_table, | ||
[:tag_id, :taggable_id, :taggable_type, :context, :tagger_id, :tagger_type], | ||
unique: true, name: 'taggings_idx' | ||
end | ||
|
||
def self.down | ||
remove_index ActsAsTaggableOn.tags_table, :name | ||
|
||
remove_index ActsAsTaggableOn.taggings_table, name: 'taggings_idx' | ||
|
||
add_index ActsAsTaggableOn.taggings_table, :tag_id unless index_exists?(ActsAsTaggableOn.taggings_table, :tag_id) | ||
add_index ActsAsTaggableOn.taggings_table, [:taggable_id, :taggable_type, :context], name: 'taggings_taggable_context_idx' | ||
end | ||
end |
20 changes: 20 additions & 0 deletions
20
db/migrate/20200214025009_add_taggings_counter_cache_to_tags.acts_as_taggable_on_engine.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# This migration comes from acts_as_taggable_on_engine (originally 3) | ||
if ActiveRecord.gem_version >= Gem::Version.new('5.0') | ||
class AddTaggingsCounterCacheToTags < ActiveRecord::Migration[4.2]; end | ||
else | ||
class AddTaggingsCounterCacheToTags < ActiveRecord::Migration; end | ||
end | ||
AddTaggingsCounterCacheToTags.class_eval do | ||
def self.up | ||
add_column ActsAsTaggableOn.tags_table, :taggings_count, :integer, default: 0 | ||
|
||
ActsAsTaggableOn::Tag.reset_column_information | ||
ActsAsTaggableOn::Tag.find_each do |tag| | ||
ActsAsTaggableOn::Tag.reset_counters(tag.id, ActsAsTaggableOn.taggings_table) | ||
end | ||
end | ||
|
||
def self.down | ||
remove_column ActsAsTaggableOn.tags_table, :taggings_count | ||
end | ||
end |
15 changes: 15 additions & 0 deletions
15
db/migrate/20200214025010_add_missing_taggable_index.acts_as_taggable_on_engine.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# This migration comes from acts_as_taggable_on_engine (originally 4) | ||
if ActiveRecord.gem_version >= Gem::Version.new('5.0') | ||
class AddMissingTaggableIndex < ActiveRecord::Migration[4.2]; end | ||
else | ||
class AddMissingTaggableIndex < ActiveRecord::Migration; end | ||
end | ||
AddMissingTaggableIndex.class_eval do | ||
def self.up | ||
add_index ActsAsTaggableOn.taggings_table, [:taggable_id, :taggable_type, :context], name: 'taggings_taggable_context_idx' | ||
end | ||
|
||
def self.down | ||
remove_index ActsAsTaggableOn.taggings_table, name: 'taggings_taggable_context_idx' | ||
end | ||
end |
15 changes: 15 additions & 0 deletions
15
db/migrate/20200214025011_change_collation_for_tag_names.acts_as_taggable_on_engine.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# This migration comes from acts_as_taggable_on_engine (originally 5) | ||
# This migration is added to circumvent issue #623 and have special characters | ||
# work properly | ||
if ActiveRecord.gem_version >= Gem::Version.new('5.0') | ||
class ChangeCollationForTagNames < ActiveRecord::Migration[4.2]; end | ||
else | ||
class ChangeCollationForTagNames < ActiveRecord::Migration; end | ||
end | ||
ChangeCollationForTagNames.class_eval do | ||
def up | ||
if ActsAsTaggableOn::Utils.using_mysql? | ||
execute("ALTER TABLE #{ActsAsTaggableOn.tags_table} MODIFY name varchar(255) CHARACTER SET utf8 COLLATE utf8_bin;") | ||
end | ||
end | ||
end |
23 changes: 23 additions & 0 deletions
23
db/migrate/20200214025012_add_missing_indexes_on_taggings.acts_as_taggable_on_engine.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# This migration comes from acts_as_taggable_on_engine (originally 6) | ||
if ActiveRecord.gem_version >= Gem::Version.new('5.0') | ||
class AddMissingIndexesOnTaggings < ActiveRecord::Migration[4.2]; end | ||
else | ||
class AddMissingIndexesOnTaggings < ActiveRecord::Migration; end | ||
end | ||
AddMissingIndexesOnTaggings.class_eval do | ||
def change | ||
add_index ActsAsTaggableOn.taggings_table, :tag_id unless index_exists? ActsAsTaggableOn.taggings_table, :tag_id | ||
add_index ActsAsTaggableOn.taggings_table, :taggable_id unless index_exists? ActsAsTaggableOn.taggings_table, :taggable_id | ||
add_index ActsAsTaggableOn.taggings_table, :taggable_type unless index_exists? ActsAsTaggableOn.taggings_table, :taggable_type | ||
add_index ActsAsTaggableOn.taggings_table, :tagger_id unless index_exists? ActsAsTaggableOn.taggings_table, :tagger_id | ||
add_index ActsAsTaggableOn.taggings_table, :context unless index_exists? ActsAsTaggableOn.taggings_table, :context | ||
|
||
unless index_exists? ActsAsTaggableOn.taggings_table, [:tagger_id, :tagger_type] | ||
add_index ActsAsTaggableOn.taggings_table, [:tagger_id, :tagger_type] | ||
end | ||
|
||
unless index_exists? ActsAsTaggableOn.taggings_table, [:taggable_id, :taggable_type, :tagger_id, :context], name: 'taggings_idy' | ||
add_index ActsAsTaggableOn.taggings_table, [:taggable_id, :taggable_type, :tagger_id, :context], name: 'taggings_idy' | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters