From f2d3c98ddba8960d582a28f419577710394bc969 Mon Sep 17 00:00:00 2001 From: jodyalbritton Date: Sat, 29 Sep 2012 18:38:53 -0500 Subject: [PATCH] update the way mentions and hashtags are handled --- app/helpers/application_helper.rb | 8 ++++---- app/models/tag.rb | 5 ++++- db/migrate/20120929173129_add_slug_to_tags.rb | 1 + db/migrate/20120929232757_add_index_to_tags.rb | 5 +++++ db/schema.rb | 3 ++- 5 files changed, 16 insertions(+), 6 deletions(-) create mode 100644 db/migrate/20120929232757_add_index_to_tags.rb diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 2650a39..c8492ca 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -16,16 +16,16 @@ def mention_linker(content) if $1 == "@" linker = User.where(:username => $2) if linker.any? - link_to $2, user_path(linker.last.username) + link_to "@"+$2, user_path(linker.last.id) else $2 end elsif $1 == "#" - linker = Tag.where(:content => $2) + linker = Tag.where(:content => $2.downcase) if linker.any? - link_to $2, tag_path(linker.last.id) + link_to "#"+$2.downcase, tag_path(linker.last.id) else - $2 + $2.downcase end end end diff --git a/app/models/tag.rb b/app/models/tag.rb index 512eba7..874c953 100644 --- a/app/models/tag.rb +++ b/app/models/tag.rb @@ -1,4 +1,7 @@ class Tag < ActiveRecord::Base + extend FriendlyId + friendly_id :content, use: :slugged + attr_accessible :content has_and_belongs_to_many :activities @@ -10,7 +13,7 @@ def trend_count def self.process_tags(activity_id) p = Activity.find(activity_id) p.tag_list.each do |tag| - t = find_or_initialize_by_content(tag) + t = find_or_initialize_by_content(tag.downcase) t.activities << p t.save end diff --git a/db/migrate/20120929173129_add_slug_to_tags.rb b/db/migrate/20120929173129_add_slug_to_tags.rb index 9308162..c21aca1 100644 --- a/db/migrate/20120929173129_add_slug_to_tags.rb +++ b/db/migrate/20120929173129_add_slug_to_tags.rb @@ -1,5 +1,6 @@ class AddSlugToTags < ActiveRecord::Migration def change add_column :tags, :slug, :string + end end diff --git a/db/migrate/20120929232757_add_index_to_tags.rb b/db/migrate/20120929232757_add_index_to_tags.rb new file mode 100644 index 0000000..3818b00 --- /dev/null +++ b/db/migrate/20120929232757_add_index_to_tags.rb @@ -0,0 +1,5 @@ +class AddIndexToTags < ActiveRecord::Migration + def change + add_index :tags, :slug + end +end diff --git a/db/schema.rb b/db/schema.rb index 29fa555..c831dd6 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20120929182316) do +ActiveRecord::Schema.define(:version => 20120929232757) do create_table "activities", :force => true do |t| t.integer "user_id" @@ -162,6 +162,7 @@ end add_index "tags", ["content"], :name => "index_tags_on_content", :unique => true + add_index "tags", ["slug"], :name => "index_tags_on_slug" create_table "users", :force => true do |t| t.string "email", :default => "", :null => false