Return ActiveRecord query as variable, not hash?

Try: foo = MyModel. Find(:all, :select => 'year'). Map(&:year) You also can call uniq() on the result to remove duplicates foo = MyModel.

Find(:all, :select => 'year'). Map(&:year). Uniq This is the short form for foo = MyModel.

Find(:all, :select => 'year'). Map{ |model| model. Year } This loops over the MyModel Array and crates a new array of the return values with in the block ( model.

Year ) or even shorter code, but first calling everything from db: foo = MyModel.all. Map(&:year).

Try: @foo = MyModel. Find(:all, :select => 'year'). Map(&:year) You also can call .uniq() on the result to remove duplicates.

@foo = MyModel. Find(:all, :select => 'year'). Map(&:year).

Uniq This is the short form for @foo = MyModel. Find(:all, :select => 'year'). Map{ |model| model.

Year } This loops over the MyModel Array and crates a new array of the return values with in the block (model. Year). Or even shorter code, but first calling everything from db: @foo = MyModel.all.

Map(&:year).

– yuval Jun 28 '10 at 18:08 hope my update helps to understand – jigfox Jun 28 '10 at 18:12.

If you don't want to instantiate models, you'd do it this way: MyModel.connection. Select_values("SELECT year FROM my_models") This will return an Array of String objects. Then you can transform using Ruby tools as you see fit.

You can use map to change every value in an array. Example: @foo = MyModel. Find(:all, :select => 'year').

Map { |model_object| model_object. Year }.

You need to put a dot between 'year') and map! , and why do you use map! , map would just work fine here, because your assigning the result to a new variable – jigfox Jun 28 '10 at 18:14 Good catch.

I edited it to use map. – hundredwatt Jun 28 '10 at 18:23.

This would modify the query parameter name on each links. This would modify each link’s url_option. And :action might be the keys in common.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions