Ruby on Rails - Import CSV file -
I am following this tutorial but doing something wrong because I get a silly error when I make my own I'm trying to object Undefined Continuous Quanta Contents Controller :: False I can read the file without problems, but this error is giving me a headache! Any help would be appreciated! The method of importing into my controller (cuenta_contable_controller.rb) looks like this; and my model (cuenta_contable.rb) like this You are using But neither is necessary; Not too bad and more-bracketed: You may use an assistant to turn on line 5 in the boolean and delete it from the mainline code. < / Div>
Class quantacontributions controller & lt; ApplicationController .... DRF Upload (Parameters) logger.info "** File Loaded ***" infile = params [: file] .read n, errs = 0, [] @archivo = [] SV.prese ( Infilay). Line | N + = 1 # SKIP: Header i.e. The first row or empty line next if n == 1 or row.join.blank? Cuenta_contable = CuentaContable.build_from_csv (line) if cuenta_contable.valid? Cuenta_contable.save @archivo & lt; & Lt; Row and forgets & lt; & Lt; End of line end logger.info flash [: success] = "Las Quant's Contrables Fireon Corps." Response_to do | Format | Format.html # index.html.erb format.json {Render: json = & gt; @ Archivo} and end
class quanta contextable & lt; ActiveRecord :: Base .... def self.build_from_csv (line) ultimo_nivel = (line [5] .downdown == "C")? (True): (false) #cuenta = find_or_initialize_by_cuenta ("# {line {0}} - # {line {1}} - # {line {2}}" # Create an e-mail or new quanta for the existing customer = CuentaContable.new (cuenta = & gt; "# {line [0]} - # {line {1}} - # {line {2}}" ,: descripcion => "# {line [3] .titleize } ",: Categoria_cuenta = & gt;" # {line [4] .titleize} ",: ultimo_nivel => ultimo_nivel) return cuenta end
true instead of
true (similar to
false ).
#Ick! Ultimo_nivel = (line [5]. Downcas == "C")? (True): (false) #Good! Ultimo_nivel = Row [5]. Downcase == "C"
Comments
Post a Comment