Lut Lut -4 years ago 147
Ruby Question

CSV Import: undefined method `path'

I am trying to import a CSV with addresses. I am requiring 'csv' at the controller. However I get this error:

NoMethodError in AddressesController#import_addresses

undefined method `path' for "testimport.csv":String


Address Controller

class AddressesController < ApplicationController

require 'csv'

def import_addresses
redirect_to root_url, notice: "Addresses imported."

Address Model

def self.import(file)
CSV.foreach(file, headers: true) do |row|
Address.create! row.to_hash


Answer Source

please try this one form_tag(import_addresses_path, :multipart => true) do * The multipart option is not part of the url_for options. so you have to make them explicitly separate* so the form_tag isn't generated right and string is sent to controller, not the object.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download