开发者

Rails: awesome_nested_set issues

开发者 https://www.devze.com 2023-04-01 02:20 出处:网络
I am using the awesome_nested_set to do a simple drag and drop reordering of news items and the post happens but the position field in my DB is not updated...

I am using the awesome_nested_set to do a simple drag and drop reordering of news items and the post happens but the position field in my DB is not updated...

Here is my model:

class NewsItem < ActiveRecord::Base
  translates :title, :body, :external_url

  attr_accessor :locale, :position # to hold temporarily

  alias_attribute :content, :body
  validates :title, :content, :publish_date, :presence => true

  has_friendly_id :title, :use_slug => true

  acts_as_indexed :fields => [:title, :body]
  acts_as_nested_set

  default_scope :order => "publish_date DESC"

  # If you're using a named scope that includes a changing variable you need to wrap it in a lambda
  # This avoids the query being cached thus becoming unaffected by changes (i.e. Time.now is constant)
  scope :not_expired, lambda {
    news_items = Arel::Table.new(NewsItem.table_name)
    where(news_items[:expiration_date].eq(nil).or(news_items[:expiration_date].gt(Time.now)))
  }
  scope :published, lambda {
    not_expired.where("publish_date < ?", Time.now)
  }
  scope :latest, lambda { |*l_params|
    published.limit( l_params.first || 10)
  }

  # rejects any page that has not been translated to the current locale.
  scope :translated, lambda {
    pages = Arel::Table.new(NewsItem.table_name)
    translations = Arel::Table.new(NewsItem.translations_table_name)

    includes(:translations).where(
      translations[:locale].eq(Globalize.locale)).where(pages[:id].eq(translations[:news_item_id]))
  }

  def not_published? # has the published date no开发者_如何学编程t yet arrived?
    publish_date > Time.now
  end

  # for will_paginate
  def self.per_page
    20
  end

end

Anyone know why this wouldn't work?

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号