Forum: Ruby on Rails Only iterating over the middle content_columns?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Efcfed8f31bf296dbfcb60ecd64239cc?d=identicon&s=25 Duane (Guest)
on 2006-02-03 21:38
Standard behavior for the list action is to use content_columns to get
all the fields of a model and then do something with them.  I'd like to
ignore some of them and iteratre over the rest.  For instance I may have
A B C D ... X Y Z  and I'd like to do something special with A and B and
then Y and Z, but in the middle I'd definitely like a loop to say
"Whatever else is in the middle, here."

What's my option there?  content_columns (or column_names) just seems to
iterate over everything.  I'm currently looking at maybe using "slice"
on the result but I haven't gotten that to work syntactically, yet.  Is
there a different way?

d
Ad7805c9fcc1f13efc6ed11251a6c4d2?d=identicon&s=25 Alex Young (Guest)
on 2006-02-06 11:38
(Received via mailing list)
Duane wrote:
> Standard behavior for the list action is to use content_columns to get
> all the fields of a model and then do something with them.  I'd like to
> ignore some of them and iteratre over the rest.  For instance I may have
> A B C D ... X Y Z  and I'd like to do something special with A and B and
> then Y and Z, but in the middle I'd definitely like a loop to say
> "Whatever else is in the middle, here."

a,b = list[0..1]
y,z = list[-2..-1]
remainder = list[2..-3]

That sort of syntax should do it...
This topic is locked and can not be replied to.