Skip to content

Instantly share code, notes, and snippets.

@mhinton
Created July 17, 2010 20:33
Show Gist options
  • Save mhinton/479837 to your computer and use it in GitHub Desktop.
Save mhinton/479837 to your computer and use it in GitHub Desktop.
ActiveRecord Error
def update_order
@idlist = params[:id]
@todays_list = ActionList.today.first
@todays_list.reorder_action_items(@idlist)
end
class ActionList < ActiveRecord::Base
has_many :action_items
scope :today, lambda {
where("day = ?", Date.today)
}
scope :recent, lambda {
where("day >= ? and day < ?", Date.today - 5.days, Date.today).includes(:action_items)
}
def reorder_action_items(new_order)
new_order.each_with_index do |item, index|
debugger
action_item = self.action_items.find(item)
action_item.sort_order = index + 1
action_item.save
end
end
end
class ActionItem < ActiveRecord::Base
belongs_to :action_list
default_scope order("sort_order asc, created_at asc")
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment