我如何更新和显示当前用户的标签,标记有acts_as_taggable_on? [英] How do I update & display a current user's tags, tagged with acts_as_taggable_on?

查看:179
本文介绍了我如何更新和显示当前用户的标签,标记有acts_as_taggable_on?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不确定如何在视图中显示属于使用Omniauth登录的用户的标签.

I'm not sure how to display tags in my view that belong to a user logged in with Omniauth.

视图中的页面会加载随机的照片和与之关联的标签(通过可从该页面更新的表单).它可以工作,但是当我使用Facebook帐户A登录时,它将显示与使用Facebook帐户B登录时完全相同的标签.

A page in the view loads a random photos and tags associated to it (via a form that can be updated from that page). It works, but when I log in with Facebook account A, it will show exactly the same tags as if I log in with Facebook account B.

通过下面的代码获取whiny nil错误称呼id为nil,错误地将其设为4-如果您确实想要id为nil,请使用object_id

Getting the whiny nil error with this below Called id for nil, which would mistakenly be 4 -- if you really wanted the id of nil, use object_id

视图是:

<%= render 'tag_form' %>

已更新:表单为:

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

# <%= f.text_field :tag_list %> was changed to the one above.

标签也在用户的仪表板中调用,如下所示(当前为空,因为显然我现在无法更新标签):

The tags are also called in a user's dashboard, as below (currently empty because obviously I can't update tags right now):

<%= brand.taggings( :tagger_id => current_user.id, :tagger_type => 'User').collect{|tagging| tagging.tag.to_s}.join(", ") %>

显示当前用户的应用程序控制器

The application controller showing current user

def current_user  
  @current_user ||= User.find(session[:user_id]) if session[:user_id]  
end

品牌控制者

helper_method :current_user 

def index
  @brands = Brand.all
  @brand = Brand.order("RANDOM()").first
end

已添加:品牌模型

attr_accessible :name, :tag_list, :current_user
acts_as_taggable_on :tags

belongs_to :user

before_save :set_tag_owner

def set_tag_owner
  set_owner_tag_list_on(@brand, :tags, self.tag_list)
  self.tag_list = nil
end

推荐答案

只是在IRC上与您交谈,但是您可以尝试:

Was just talking to you on IRC, but can you try:

<%=调试@ brand.tag_list%>

<%= debug @brand.tag_list %>

在您看来.您的用户没有标签.如果您要为用户添加标签,请在用户模型中添加一个act_as_taggable

in your view. Your user doesn't have tags. If you want tags for your user add a acts_as_taggable in your User model

似乎您想找到由current_user标记的@brand标记.在这种情况下:

It seems you want to find tags of @brand tagged by current_user. In that case:

<%= debug @brand.taggings(:tagger_id => current_user.id, :tagger_type => 'User').all %> 

这篇关于我如何更新和显示当前用户的标签,标记有acts_as_taggable_on?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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