0
我得到這個錯誤在我的瀏覽器,當我去我的文章的「編輯」頁面:從NoMethod錯誤我
博客/應用/視圖/用品/ _form.html.erb
undefined method `tag_list' for #<Article:0x007ffb52130678>
提取的源(左右線#20):
18: <p>
19: <%= f.label :tag_list %><br />
20: <%= f.text_field :tag_list %>
21: </p>
我的文章型號:
class Article < ActiveRecord::Base
attr_accessible :title, :body, :tag_list, :image
has_many :comments
has_many :taggings
has_many :tags, through: :taggings
has_attached_file :image
def tag_list=(tags_string)
tag_names = tags_string.split(",").collect{ |s| s.strip.downcase }.uniq
new_or_found_tags = tag_names.collect { |name| Tag.find_or_create_by_name(name) }
self.tags = new_or_found_tags
end
end
我有一個文章模型,有很多標籤。這種關係通過稱爲標籤的另一種模式來表示。同樣,我的文章模型/控制器的編輯頁面出現此錯誤。我的博客應用說我的:tag_list方法沒有方法錯誤,但它存在於我的文章模型中。我明顯錯過了一些東西,需要填補這個空白。
如果將attr_reader:tag_list添加到模型中,它有幫助嗎? – Rebitzele
工作的聖潔廢話。道具給你。如果你想解釋爲什麼attr_reader:tag_list作爲答案,我很樂意給你豎起大拇指! – andy4thehuynh
當然,我添加了一個解釋。讓我知道它是否合理。 – Rebitzele