I have a question about acts_as_taggable_on. I'm making a BBS and want to display link tags. However, my website can display only strings not links. So I want to put link to strings.
I want to link_to each tags#show.
Now some tags are saved in Tag
table and this table have these column(id, name, created_count)
This is my code:
post.rb
def save_tags
array = self.check_taggable_word(self.title)
self.tag_list.add(array, parse: true)
end
def tag_lists
tag_lists = self.tag_list
end
def check_taggable_word(text)
ary = Array.new
nm = Natto::MeCab.new
nm.parse(text) do |n|
ary<<n.surface
end
tags = ActsAsTaggableOn::Tag.pluck(:name)
return ary & tags
end
show.html.erb (post)
Tag:
<% @post.save_tags %>
<%= @post.tag_list %>
posts_controller.rb
def show
@post = Post.find(params[:id])
@category = @post.category
end
routes.rb
Rails.application.routes.draw do
root 'static_pages#home'
get '/about' => 'static_pages#about'
get '/contact' => 'static_pages#contact'
resources :categories do
resources :posts
end
resources :posts do
resources :comments
end
resources :tags, only: [:index, :show]
end