Created
July 17, 2010 20:33
-
-
Save mhinton/479837 to your computer and use it in GitHub Desktop.
ActiveRecord Error
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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