मुझे इन दो कक्षाएं मिल गई हैं।रेल: यदि has_many संबंध बदल गया है
class Article < ActiveRecord::Base
attr_accessible :body, :issue, :name, :page, :image, :video, :brand_ids
has_many :publications
has_many :docs, :through => :publications
end
class Doc < ActiveRecord::Base
attr_accessible :issue_id, :cover_id, :message, :article_ids, :user_id, :created_at, :updated_at, :issue_code, :title, :template_id
has_many :publications, dependent: :destroy
has_many :articles, :through => :publications, :order => 'publications.position'
has_many :edits, dependent: :destroy
accepts_nested_attributes_for :articles, allow_destroy: false
end
मैं एक सशर्त बयान कैसे लिख सकता हूँ अगर @doc.articles
@doc
को अद्यतन करने के बाद बदल गया है को देखने के लिए चाहते हैं?
if @doc.articles.changed?
...
end
उपर्युक्त मुझे एक त्रुटि देता है। मुझे सही वाक्यविन्यास नहीं मिल रहा है।
बिल्कुल सही! धन्यवाद। –
उस मामले के बारे में क्या है जहां सूची में has_many जोड़ा गया है? यह एक बदलाव है, लेकिन क्या यह इस तरह से पता लगाया जाएगा? – aaaronic
क्या यह पता लगाने का कोई तरीका है कि @ person.task_ids_changed ?. मैं यह जानना चाहता हूं कि _ids सरणी बदलती है या नहीं। – Stone