我不知道如何顯示在我看來屬於用戶與Omniauth登錄標籤。如何更新和顯示當前用戶的標籤,標籤的acts_as_taggable_on?
在瀏覽網頁加載與之相關聯的一個隨機的照片和標籤(通過可從該頁面更新的形式)。它的工作原理,但是當我用Facebook帳戶日誌中,它會顯示完全一樣的標籤,如果我的Facebook帳戶B.
掌握這個愛發牢騷零誤差低於名爲id爲零,登入其會誤爲4 - 如果你真的想零的ID,請使用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.
的標籤也被稱爲在用戶的儀表盤,如下(目前爲空的,因爲很明顯,我現在不能更新標籤):
<%= brand.taggings(:tagger_id => current_user.id, :tagger_type => 'User').collect{|tagging| tagging.tag.to_s}.join(", ") %>
應用控制器顯示當前用戶
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
劉若英,你的幫助是非常寶貴的。我最後一個問題是條件tagger_id => current.user.id不起作用。目前所有保存的標籤仍然顯示。服務器顯示((taggings.tagger_id IS NULL AND taggings.context ='tags')))這可能是爲什麼。 – Simpleton
上面的代碼在標籤之後需要一個.where。我補充說,現在它做正確的事它並不表明不是當前用戶的,但現在也有出於同樣的原因我的上述評論(tagger_id是NULL)無標籤的標籤,以便它沒有標籤顯示。 – Simpleton
啊,我懷疑它與部分形式有關。表單文本字段加載之前添加的標籤,但加載所有標籤,而不僅僅用於current_user。所以當它保存時,它不會保存到current_user.id,而是保存爲NULL。如何解決這個問題? – Simpleton