Your first idea is something like what I was aiming for, actually. What I haven't been able to find is if .first? is a valid method to attach the array. If .first? isn't a pre-built method for Ruby(onRails), then I'm wondering if there's a way to write the expression anything like this:
In the controller, I would first declare
Code:
def list
@posts = Post.find_all
end
In the main page code, I would iterate through the first 3 using
Code:
<% @posts.values_at(0..2).each do |post| %>
The thing that stumps me is if I can set a helper function that would either say
Code:
if posts.first?
divclass = 'show'
#or
if posts.index=0
divclass = 'show'
Like I said, I know that PHP can keep track of exactly what index/key in an array is being currently iterated through, but I'm not sure if RoR has that same functionality.
Bookmarks