私はacts-as-taggable-onを使用しています。私は複数のアプローチを試みましたが、どちらも機能しません。ビューで投稿はチェックボックスで「タグ付け」されるようにするにはどうすればよいですか?
:コントローラで
def add_politics; self.tag_list.add('politics'); end
def add_tech; self.tag_list << 'tech'; end
def add_entertainment; self.tag_list << 'entertainment'; end
def add_sports; self.tag_list << 'sports'; end
def add_science; self.tag_list << 'science'; end
def add_crime; self.tag_list << 'crime'; end
def add_business; self.tag_list << 'business'; end
def add_social; self.tag_list << 'social'; end
def add_nature; self.tag_list << 'nature'; end
def add_other; self.tag_list << 'other'; end
:モデルで
<%= check_box("post", "add_politics", {:class=> "post"}) %>
<%= f.label :politics %>
<%= check_box("post", "add_tech") %>
<%= f.label :tech, 'Technology' %>
<%= f.check_box :entertainment %>
<%= f.label :entertainment %>
<%= f.check_box :sports %>
<%= f.label :sports %>
<%= f.check_box :science %>
<%= f.label :science %>
<%= f.submit %>
@post.tag_list << 'politics' if params[:post][:politics]
@post.tag_list << 'tech' if params[:post][:tech]
@post.tag_list << 'entertainment' if params[:post][:entertainment]
@post.tag_list << 'sports' if params[:post][:sports]
@post.tag_list << 'science' if params[:post][:science]
@post.tag_list << 'crime' if params[:post][:crime]
@post.tag_list << 'business' if params[:post][:business]
@post.tag_list << 'social' if params[:post][:social]
@post.tag_list << 'nature' if params[:post][:nature]
@post.tag_list << 'other' if params[:post][:other]
何が起こって終了すると、その唯一の娯楽、スポーツ、科学です。 ..その他は<%= f.check_box:tag%>形式のものなので表示されます。しかし、チェックを外すかチェックしても違いはありません。これらのタグは常に表示されます。一体何が起こっているの?
:コントローラで
:ここではどのようにですか?リファクタリングを少し試してみてください –