ruby on rails - Return a number from collection_select -


i using input field collection, drawn array in model. works well, return different value actual column in table. i'm using simple_form.

model

task_options = %w(detection cloning sequencing primer_list primer_check) 

view

<%= f.input :primer_task, :collection => primer3batch::task_options, :label => 'task' %> 

i might want return this:

{1 => 'detection', 2 => 'cloning'... etc 

or this:

{'ab' => 'detection, 'c' => 'cloning' .... 

that is: page display detection, cloning etc database column store 1,2 or ab, c i've guessed can done hash can't quite work out syntax.

a = [] %w(detection cloning sequencing primer_list primer_check).each.with_index(1) |it,ind|     << [ind,it] end hash[a] # => {1=>"detection", #     2=>"cloning", #     3=>"sequencing", #     4=>"primer_list", #     5=>"primer_check"} 

using enumerable#each_with_object

a = %w(detection cloning sequencing primer_list primer_check) a.each_with_object({}) {|it,h| h[a.index(it) + 1 ] = } # => {1=>"detection", #     2=>"cloning", #     3=>"sequencing", #     4=>"primer_list", #     5=>"primer_check"} 

Comments

Popular posts from this blog

Ansible - ERROR! the field 'hosts' is required but was not set -

customize file_field button ruby on rails -

SoapUI on windows 10 - high DPI/4K scaling issue -