Sha256: d5425ff1d47b336462cd67ad0740856a60acd2bf63e6ed9f378598a74e2e75c1

Contents?: true

Size: 527 Bytes

Versions: 1

Compression:

Stored size: 527 Bytes

Contents

class GroupsController < ApplicationController
  def create
    user_prefix = /^user_/
    @groups = Group.csv_import(params[:group][:file], find_key: :name) do |group, _params, i|
      user_params = _params.select{|k, v| k =~ user_prefix }.to_a.inject({}){|hash, (k, v)|
        hash[k.gsub(user_prefix, '')] = v
        hash
      }
      user_params
      user = User.where(name: user_params['name']).first_or_initialize
      user.attributes = user_params
      group.users << user
    end

    render text: nil
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
csv_rails-0.7.0 test/dummy/app/controllers/groups_controller.rb