Category: Ruby on Rails

Ruby, turn array of hashes into single hash

January 16, 2014 at 11:59 pmCategory:Ruby on Rails

I have the following Array of Hashes:

I need to turn it into:

or:

Can I do this in a clean & functional way?

Something like this:

if you want the other way:

incorporating the suggestion from @squiguy:

To display the searched item in the same page

October 10, 2013 at 10:58 pmCategory:Ruby on Rails

The following code present in srches_controller

The searched item is now displayed in the new search page.
But I need to display the searched item in the same index page.
What is the solution?

You can pass parameter search to index page & search your results with:

or you can set scope in your model:

and call it in controller with:

rails input selected values from params to select_tag (multiple => true)

October 4, 2013 at 10:58 pmCategory:Ruby on Rails

I want to keep the select_tag(:multiple => true) options to be selected which were selected by user once search is performed

Suppose a user select 4 values from the select tag then for values should be selected,
How can we pass this 4 values to the select_tag?

I tried using :selected => params['values[]'] yet this doesnt works for multiple true

Any assist will be appreciated

Ref this & options_for_select

Something like following