RubyFlow The Ruby and Rails community linklog

×

The Ruby and Rails community linklog

Made a library? Written a blog post? Found a useful tutorial? Share it with the Ruby community here or just enjoy what everyone else has found!

Scope Columns

ColumnScope to select only certain values from your DB. I often need only single attributes of an ActiveRecord instance. In the past I used something like select_values(SELECT_SQL) or find(:all, :select => SELECT_SQL_FRAGMENT).map! { |r| [r.title, r.teaser]} to conservativly get them. After some time I felt the redundant code tiring and wrote this tiny plugin on top of named scopes. Usage examples: Article.selects(:title_and_teaser).with_author.all # => [<Article ...] Product.ordered_by_name.select_all(:name_and_prize) # => [['Apple Pie', 3.80], ...] You can find the source and more examples in my repository @ github.

Post a comment

You can use basic HTML markup (e.g. <a>) or Markdown.

As you are not logged in, you will be
directed via GitHub to signup or sign in