Friday, 15 May 2015

passing array as a parameter - ruby -



passing array as a parameter - ruby -

this within part controller file def create postal_code_list = params[:region].delete(:postal_code_list) @region = region.new(params[:region]) authorize! :create, @region assign_postal_codes(postal_code_list) this within seed file region = region.create({ name: "region1", postal_code_list: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] })

i attempting create few default values web app in testing. exceptionally new ruby, reason such basic question. when run in debug mode, page displays name:region1, postal codes not show up. i'm unsure how pass postal_code_list array controller file. missing?

if want create seed regions seed run steps:

in seeds.rb

[1, 2, 3, 4, 5, 6, 7, 8, 9, 10].each |rc| region.create(name: "region#{rc}", postal_code_list: rc} end

and in command line:

rake db:seed

this create 10 regions named: "region1", "region2"... , postal_code_list: 1, 2...

your controller doing nothign region.create doing query, not request.

ruby-on-rails ruby arrays

No comments:

Post a Comment