当前用户如何才能将rails表单过滤为仅显示不带标签的对象? [英] How can a rails form be filtered to show only objects without tags, and by a current user?

查看:67
本文介绍了当前用户如何才能将rails表单过滤为仅显示不带标签的对象?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用acts_as_taggable_on,并且标签与品牌模型相关联.用户通过用户模型,然后通过部分表单将标签添加到每个品牌.问题在于,partial表单(在控制器的更新方法中)显示了所有特定于该品牌实例的标签,而不是仅显示当前用户的tagger_id所标记的那些标签.

I'm using acts_as_taggable_on and tags are associated to a Brand model. Users, via a User model, then add tags to each brand via a form partial. The problem is that the form partial (in an update method in the controller), shows all the tags specific to the brand instance, instead of showing only the ones that are tagged by the current user's tagger_id.

第二部分是我希望表单仅显示当前用户还没有标签的品牌实例.我在下面的品牌模型中定义了空标签,但不知道如何在表单字段中调用它们.

The second part to this is that I want the form to only show brand instances that have no tags by the current user yet. I have defined the empty tags in the brand model below but don't know how to call them up in the form fields.

表单视图

<%= form_for @brand, :html => {:multipart => true} do |f| %>  
<%= f.label :tag_list, "Your tags" %>  <%= f.text_field :tag_list %>
<%= f.submit "Tag" %></p>

控制器

@brand = current_user.brands.includes(:taggings).where(:taggings => { :id => nil } ).order("RANDOM()").first

推荐答案

问题的第一部分通过在表单中​​添加以下内容来解决:

The first part to the question is solved by added the following to the form:

<%= f.label :tag_list, "Your tags" %>  <%= f.text_field :tag_list, :value => @brand.tags_from(current_user) %>

这篇关于当前用户如何才能将rails表单过滤为仅显示不带标签的对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆