Prev | Current Page 225 | Next

Kevin Marshall, Chad Pytel, and Jon Yurek

"Pro Active Record: Databases with Ruby and Rails"

It should be an integer column, and it is usually called position by
default. You can name it anything you wish, as long as you specify its name. Typically, the
default name is good enough.
What acts_as_list Gives You
Now that you??™ve got your Active Record models set up to act as a list, you??™re probably thinking,
???Now what? What did that work actually get me???? Well, believe it or not, a lot! You now have 13
different list-like methods you can use to examine and manipulate your collection. We??™ll use
our Top Ten example:
class TopTenTopic < ActiveRecord::Base
has_many :top_ten_items
end
class TopTenItems < ActiveRecord::Base
belongs_to :top_ten_topics
acts_as_list :scope => :top_ten_topic
end
todayslist = TopTenTopic(1)
listdetails = todayslist.top_ten_items
We??™ll go over the methods we get from acts_as_list in the following sections.
insert_at(value)
This method changes the value of the position column to the value specified and moves the
values of the other items as needed to correctly insert an item at this spot.


Pages:
213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237