我如何才能使帖子被“标记”?通过复选框?
我正在使用“acts-as-ttagable-on”。我尝试了多种方法,但没有一个有效。
在视图上:
<%= 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 %>
在模型中:
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
在控制器中:
@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%> 。格式。但取消选中或选中它们并没有什么区别——这些类型的标签将始终出现。到底是怎么回事?
I'm using acts-as-taggable-on. I've tried multiple approaches but none of them work.
On the view:
<%= 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 %>
In the model:
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
In the controller:
@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]
What ends up happening is that only entertainment, sports, science...other get displayed because those are the ones that have <%=f.check_box :tag%> format. But unchecking or checking them doesn't make a difference -- those types of tags will always appear. What the heck is going on?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我修好了。具体方法如下:
在控制器中:
I fixed it. Here's how:
In the controller: