У меня возникает эта запутанная ошибка рельсов. Если кто-нибудь может объяснить, что это значит, чем это будет полезноConfused on rails error
Подписка # unseen_count делегированы notification_count.unseen_count, но notification_count равна нулю: #
здесь является модель подписки
class Subscription < ActiveRecord::Base
belongs_to :user
has_one :notification_count, :dependent => :destroy
validates :user_id, :presence => true
validates :subscribe_id, :presence => true
after_create :notification_unseen_count
delegate :unseen_count, to: :notification_count, allow_nil: true
# Add the new subscription of the user with the provider
def self.add_subscription(user, subscribe)
user.subscriptions.where(:subscribe_id => subscribe.id).first_or_create
end
# Remove the subscription of the user with the provider
def self.remove_subscription(user, subscribe)
user.subscriptions.where(:subscribe_id => subscribe.id).destroy_all
end
# Get the provider with the subscription
def subscribe
User.find(subscribe_id)
end
# Mark as read the notification count as soon as the users goes to providers feed
def mark_as_read
notification_count.update(:unseen_count => 0)
end
private
# As soon as the new subscription will create the notification count will be added fot the subscriber
def notification_unseen_count
NotificationCount.create(:subscription_id => self.id)
end
end
И вот модель уведомления:
class NotificationCount < ActiveRecord::Base
belongs_to :subscription
belongs_to :premium_subscription
validates :subscription_id, :presence => true
validates :premium_subscription_id, :presence => true
# Update the notification count when the new content lived for all the subscribed users
def self.update_notification_count subscriptions
subscriptions.each{ |subscription| subscription.notification_count.update(:unseen_count => subscription.unseen_count + 1)}
end
Редактировать: Несколько часов спустя и безрезультатно. Если у кого-нибудь есть какие-либо проблемы по этой проблеме, чем пожалуйста, дайте мне знать.
Есть ли способ сделать это не ноль ... извините ... Я все еще изучаю, как все это работает. Большое вам спасибо за вашу помощь:) – Jakxna360
Вам нужно будет показать код для обеих моделей, чтобы я мог помочь дальше –
Я добавил модели. Еще раз спасибо за помощь:) – Jakxna360