Ar-Extensions & FasterCSV

6 views
Skip to first unread message

mel ram

unread,
May 21, 2008, 12:26:44 PM5/21/08
to Ruby on Rails: Talk
1. contactx = Array.new
2. if params[:dump][:dump]
3. FasterCSV.parse(params[:dump][:dump].read.chop, {:headers =>
true, :skip_blanks => true}) do |row|
4. contactx << Contact.new(
5. :FirstName => row["First Name"],
6. :LastName => row["Last Name"],
7. :email => row["Email Address"]
8. )
9. end
10. Contact.import contactx

This code works up to line 4. I get the error: "Array can't be coerced
into Fixnum"

If I change "contactx << Contact.new(..." to "Contact.create(..." so
that it uses active record to create the records, it works. So the
problem is with either line 4 or 10.

I'm stuck right now. Any ideas?

Craig Demyanovich

unread,
May 21, 2008, 12:38:32 PM5/21/08
to rubyonra...@googlegroups.com
I don't have any ideas based on what you've provided so far. Can you
show the Contact class? Can you show the full stack trace?

Craig

mel ram

unread,
May 21, 2008, 12:41:03 PM5/21/08
to Ruby on Rails: Talk
The Contact class is empty:

class Contact < ActiveRecord::Base
end

BTW, I already have require 'FasterCSV' & require 'ar-extensions' in
the environment.rb file.

On May 21, 9:38 am, "Craig Demyanovich" <cdemyanov...@gmail.com>
wrote:

mel ram

unread,
May 21, 2008, 12:42:17 PM5/21/08
to Ruby on Rails: Talk
Here is the Full Stack Trace:

C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/ar-extensions-0.7.0/lib/ar-
extensions/import.rb:272:in `+'
C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/ar-extensions-0.7.0/lib/ar-
extensions/import.rb:272:in `import_without_validations_or_callbacks'
C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/ar-extensions-0.7.0/lib/ar-
extensions/import.rb:262:in `each'
C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/ar-extensions-0.7.0/lib/ar-
extensions/import.rb:262:in `import_without_validations_or_callbacks'
C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/ar-extensions-0.7.0/lib/ar-
extensions/import.rb:243:in `import_with_validations'
C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/ar-extensions-0.7.0/lib/ar-
extensions/import.rb:202:in `import'
app/controllers/test_controller.rb:14:in `index'
C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/
action_controller/base.rb:1158:in `send'
C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/
action_controller/base.rb:1158:in `perform_action_without_filters'
C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/
action_controller/filters.rb:697:in `call_filters'
C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/
action_controller/filters.rb:689:in `perform_action_without_benchmark'
C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/
action_controller/benchmarking.rb:68:in
`perform_action_without_rescue'
C:/InstantRails/ruby/lib/ruby/1.8/benchmark.rb:293:in `measure'
C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/
action_controller/benchmarking.rb:68:in
`perform_action_without_rescue'
C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/
action_controller/rescue.rb:199:in `perform_action_without_caching'
C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/
action_controller/caching.rb:678:in `perform_action'
C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/
active_record/connection_adapters/abstract/query_cache.rb:33:in
`cache'
C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/
active_record/query_cache.rb:8:in `cache'
C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/
action_controller/caching.rb:677:in `perform_action'
C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/
action_controller/base.rb:524:in `send'
C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/
action_controller/base.rb:524:in `process_without_filters'
C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/
action_controller/filters.rb:685:in
`process_without_session_management_support'
C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/
action_controller/session_management.rb:123:in `process'
C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/
action_controller/base.rb:388:in `process'
C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/
action_controller/dispatcher.rb:171:in `handle_request'
C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/
action_controller/dispatcher.rb:115:in `dispatch'
C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/
action_controller/dispatcher.rb:126:in `dispatch_cgi'
C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/
action_controller/dispatcher.rb:9:in `dispatch'
C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.3-x86-mswin32/
lib/mongrel/rails.rb:76:in `process'
C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.3-x86-mswin32/
lib/mongrel/rails.rb:74:in `synchronize'
C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.3-x86-mswin32/
lib/mongrel/rails.rb:74:in `process'
C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.3-x86-mswin32/
lib/mongrel.rb:159:in `process_client'
C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.3-x86-mswin32/
lib/mongrel.rb:158:in `each'
C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.3-x86-mswin32/
lib/mongrel.rb:158:in `process_client'
C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.3-x86-mswin32/
lib/mongrel.rb:285:in `run'
C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.3-x86-mswin32/
lib/mongrel.rb:285:in `initialize'
C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.3-x86-mswin32/
lib/mongrel.rb:285:in `new'
C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.3-x86-mswin32/
lib/mongrel.rb:285:in `run'
C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.3-x86-mswin32/
lib/mongrel.rb:268:in `initialize'
C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.3-x86-mswin32/
lib/mongrel.rb:268:in `new'
C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.3-x86-mswin32/
lib/mongrel.rb:268:in `run'
C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.3-x86-mswin32/
lib/mongrel/configurator.rb:282:in `run'
C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.3-x86-mswin32/
lib/mongrel/configurator.rb:281:in `each'
C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.3-x86-mswin32/
lib/mongrel/configurator.rb:281:in `run'
C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.3-x86-mswin32/
bin/mongrel_rails:128:in `run'
C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.3-x86-mswin32/
lib/mongrel/command.rb:212:in `run'
C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.3-x86-mswin32/
bin/mongrel_rails:281
C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/
active_support/dependencies.rb:489:in `load'
C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/
active_support/dependencies.rb:489:in `load'
C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/
active_support/dependencies.rb:342:in `new_constants_in'
C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/
active_support/dependencies.rb:489:in `load'
C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/rails-2.0.2/lib/commands/
servers/mongrel.rb:64
C:/InstantRails/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:
27:in `gem_original_require'
C:/InstantRails/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:
27:in `require'
C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/
active_support/dependencies.rb:496:in `require'
C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/
active_support/dependencies.rb:342:in `new_constants_in'
C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/
active_support/dependencies.rb:496:in `require'
C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/rails-2.0.2/lib/commands/
server.rb:39
C:/InstantRails/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:
27:in `gem_original_require'
C:/InstantRails/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:
27:in `require'
script/server:3
-e:2:in `load'
-e:2

On May 21, 9:38 am, "Craig Demyanovich" <cdemyanov...@gmail.com>
wrote:

mel ram

unread,
May 21, 2008, 12:43:20 PM5/21/08
to Ruby on Rails: Talk
The reason it is empty is because I'm just doing a test on this Ar-
Extensions + FasterCSV combination.

mel ram

unread,
May 21, 2008, 12:48:41 PM5/21/08
to Ruby on Rails: Talk
Below is what the development.log spits out. Everything looks normal
until WARNING: Can't mass-assign these protected attributes: id.

---------------------------------
Processing TestController#index (for 127.0.0.1 at 2008-05-21 09:46:16)
[POST]
Session ID:
BAh7BzoMY3NyZl9pZCIlMDE2M2EyMzcyNmVlYTJiOTlmMmVjY2UxMTE3ODU4%0AZGQiCmZsYXNoSUM6J0FjdGlvbkNvbnRyb2xsZXI6OkZsYXNoOjpGbGFzaEhh
%0Ac2h7AAY6CkB1c2VkewA%3D--bf05bf03237b9cc7db7b01626342d20037e77773
Parameters: {"commit"=>"Submit",
"authenticity_token"=>"4eebcffb9f792f1422352b30f99e54c6e51411da",
"action"=>"index", "controller"=>"test",
"dump"=>{"dump"=>#<ActionController::UploadedStringIO:0x47b8140>}}
[4;36;1mContact Delete all (0.140000) [0m [0;1mDELETE FROM
contacts WHERE 1=1 [0m
WARNING: Can't mass-assign these protected attributes: id
WARNING: Can't mass-assign these protected attributes: id
WARNING: Can't mass-assign these protected attributes: id
WARNING: Can't mass-assign these protected attributes: id
WARNING: Can't mass-assign these protected attributes: id
[4;35;1mSQL (0.172000) [0m [0mINSERT INTO contacts
("id","FirstName","LastName","email","created_at","updated_at")
VALUES(NULL,'eve','kiti','trix...@yahoo.com','2008-05-21
09:46:16','2008-05-21 09:46:16') [0m


TypeError (Array can't be coerced into Fixnum):
C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/ar-extensions-0.7.0/
lib/ar-extensions/import.rb:272:in `+'
C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/ar-extensions-0.7.0/
lib/ar-extensions/import.rb:272:in
`import_without_validations_or_callbacks'
C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/ar-extensions-0.7.0/
lib/ar-extensions/import.rb:262:in `each'
C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/ar-extensions-0.7.0/
lib/ar-extensions/import.rb:262:in
`import_without_validations_or_callbacks'
C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/ar-extensions-0.7.0/
lib/ar-extensions/import.rb:243:in `import_with_validations'
C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/ar-extensions-0.7.0/
lib/ar-extensions/import.rb:202:in `import'
/app/controllers/test_controller.rb:14:in `index'
mswin32/bin/../lib/mongrel/rails.rb:76:in `process'
C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.3-x86-
mswin32/bin/../lib/mongrel/rails.rb:74:in `synchronize'
C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.3-x86-
mswin32/bin/../lib/mongrel/rails.rb:74:in `process'
C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.3-x86-
mswin32/lib/mongrel.rb:159:in `process_client'
C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.3-x86-
mswin32/lib/mongrel.rb:158:in `each'
C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.3-x86-
mswin32/lib/mongrel.rb:158:in `process_client'
C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.3-x86-
mswin32/lib/mongrel.rb:285:in `run'
C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.3-x86-
mswin32/lib/mongrel.rb:285:in `initialize'
C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.3-x86-
mswin32/lib/mongrel.rb:285:in `new'
C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.3-x86-
mswin32/lib/mongrel.rb:285:in `run'
C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.3-x86-
mswin32/lib/mongrel.rb:268:in `initialize'
C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.3-x86-
mswin32/lib/mongrel.rb:268:in `new'
C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.3-x86-
mswin32/lib/mongrel.rb:268:in `run'
C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.3-x86-
mswin32/lib/mongrel/configurator.rb:282:in `run'
C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.3-x86-
mswin32/lib/mongrel/configurator.rb:281:in `each'
C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.3-x86-
mswin32/lib/mongrel/configurator.rb:281:in `run'
C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.3-x86-
mswin32/bin/mongrel_rails:128:in `run'
C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.3-x86-
mswin32/lib/mongrel/command.rb:212:in `run'
C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.3-x86-
mswin32/bin/mongrel_rails:281
C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activesupport-2.0.2/
lib/active_support/dependencies.rb:489:in `load'
C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activesupport-2.0.2/
lib/active_support/dependencies.rb:489:in `load'
C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activesupport-2.0.2/
lib/active_support/dependencies.rb:342:in `new_constants_in'
C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activesupport-2.0.2/
lib/active_support/dependencies.rb:489:in `load'
C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/rails-2.0.2/lib/
commands/servers/mongrel.rb:64
C:/InstantRails/ruby/lib/ruby/site_ruby/1.8/rubygems/
custom_require.rb:27:in `gem_original_require'
C:/InstantRails/ruby/lib/ruby/site_ruby/1.8/rubygems/
custom_require.rb:27:in `require'
C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activesupport-2.0.2/
lib/active_support/dependencies.rb:496:in `require'
C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activesupport-2.0.2/
lib/active_support/dependencies.rb:342:in `new_constants_in'
C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activesupport-2.0.2/
lib/active_support/dependencies.rb:496:in `require'
C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/rails-2.0.2/lib/
commands/server.rb:39
C:/InstantRails/ruby/lib/ruby/site_ruby/1.8/rubygems/
custom_require.rb:27:in `gem_original_require'
C:/InstantRails/ruby/lib/ruby/site_ruby/1.8/rubygems/
custom_require.rb:27:in `require'
./script/server:3
-e:2:in `load'
-e:2

Rendering C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-2.0.2/
lib/action_controller/templates/rescues/layout.erb
(internal_server_error)

Craig Demyanovich

unread,
May 21, 2008, 1:07:31 PM5/21/08
to rubyonra...@googlegroups.com
Hmm. Mabye you shouldn't be importing actual AR instances? Have you
read this article?

http://www.jobwd.com/article/show/31

In it, the import is done by specifying matched arrays of columns and
values (shown near the end just before the comments).

Note that the docs for ar-extensions are still down (I notified the
author awhile ago, but he's been busy preparing for RailsConf).

Craig

mel ram

unread,
May 21, 2008, 1:10:57 PM5/21/08
to Ruby on Rails: Talk
Craig,

I've tried that as well... and it still gives the same error. I
suspect it has to do with the NULL value being passed in for the id
column (based on looking at the log). However, I am not doing anything
to specify it so I don't know why it's doing that.

BTW, Thank you for your effort so far

On May 21, 10:07 am, "Craig Demyanovich" <cdemyanov...@gmail.com>
wrote:

Craig Demyanovich

unread,
May 21, 2008, 1:20:40 PM5/21/08
to rubyonra...@googlegroups.com
So you've tried something like this and still see the same problem?

if params[:dump][:dump]
columns = [:FirstName, :LastName, :email]
values = []


FasterCSV.parse(params[:dump][:dump].read.chop, {:headers =>true,
:skip_blanks => true}) do |row|

values << [ row["First Name"], row["Last Name"], row["Email Address"] ]
end
Contact.import columns, values
end

Craig

mel ram

unread,
May 21, 2008, 1:24:32 PM5/21/08
to Ruby on Rails: Talk
Yes. Infact, I had it practical identical to that

On May 21, 10:20 am, "Craig Demyanovich" <cdemyanov...@gmail.com>
wrote:

Craig Demyanovich

unread,
May 21, 2008, 1:33:10 PM5/21/08
to rubyonra...@googlegroups.com
What about versions of Ruby, Rails, ar-extensions, FasterCSV? What
database and version of it are you using? What platform are you
running?

Craig

mel ram

unread,
May 21, 2008, 1:36:03 PM5/21/08
to Ruby on Rails: Talk
Ruby 1.8, Rails 2.0.2, AR 0.7.0, FasterCSV is the latest version, Win
XP, InstantRails, SQLite

On May 21, 10:33 am, "Craig Demyanovich" <cdemyanov...@gmail.com>
wrote:

Craig Demyanovich

unread,
May 21, 2008, 1:41:58 PM5/21/08
to rubyonra...@googlegroups.com
On Wed, May 21, 2008 at 1:36 PM, mel ram <mel...@volcanicmarketing.com> wrote:
>
> Ruby 1.8, Rails 2.0.2, AR 0.7.0, FasterCSV is the latest version, Win
> XP, InstantRails, SQLite

I don't have experience on Windows with InstantRails and SQLite. Are
you able to try a different database, such as mysql? Are you able to
try with Rails outside of InstantRails?

mel ram

unread,
May 21, 2008, 1:47:50 PM5/21/08
to Ruby on Rails: Talk
AR-extensions says its compatible with SQLite and instantrails is the
same as regular rails so it wouldn't have any effect on the problem.

On May 21, 10:41 am, "Craig Demyanovich" <cdemyanov...@gmail.com>
wrote:

mel ram

unread,
May 21, 2008, 2:15:11 PM5/21/08
to Ruby on Rails: Talk
Ok I've simplified the code to try and identify what the heck is going
on. I took out every except:

contactx = [ Contact.new( :first_name =>"First 1", :last_name
=>"Last 1", :email_address => "Email 1"),
Contact.new( :first_name =>"First
2", :last_name =>"Last 2", :email_address => "Email 2")]
Contact.import contactx

And it still won't work

Frederick Cheung

unread,
May 21, 2008, 2:23:39 PM5/21/08
to Ruby on Rails: Talk
It's a bug in ar-extensions. (and looking at the code it would seem
they were relying on something that isn't documented. The trunk
version looks to have fixed this.

Fred

Melvin Ram

unread,
May 21, 2008, 2:26:04 PM5/21/08
to rubyonra...@googlegroups.com
The trunk version? How do I get that?
--
~ mel

Melvin Ram
Volcanic Marketing
www.volcanicmarketing.com

Cell: 916.743.9369
Email: mel...@volcanicmarketing.com
AIM: melvinram916
MSN Messenger: melvi...@hotmail.com
Skype: melvinram

mel ram

unread,
May 21, 2008, 2:51:00 PM5/21/08
to Ruby on Rails: Talk
I just installed ar-ext from http://arext.rubyforge.org/svn/trunk/ar-extensions/
and that didn't change anything. Any other ideas?

On May 21, 11:26 am, "Melvin Ram" <mel...@volcanicmarketing.com>
wrote:
> MSN Messenger: melvin_...@hotmail.com
> Skype: melvinram

Frederick Cheung

unread,
May 21, 2008, 2:51:37 PM5/21/08
to Ruby on Rails: Talk


On May 21, 7:26 pm, "Melvin Ram" <mel...@volcanicmarketing.com> wrote:
> The trunk version? How do I get that?
>
It's linked from the rubyforge project page.

Fred
> MSN Messenger: melvin_...@hotmail.com
> Skype: melvinram

mel ram

unread,
May 21, 2008, 3:11:18 PM5/21/08
to Ruby on Rails: Talk
I just installed ar-ext from http://arext.rubyforge.org/svn/trunk/ar-extensions/
and that didn't change anything. Any other ideas?

On May 21, 11:51 am, Frederick Cheung <frederick.che...@gmail.com>

Frederick Cheung

unread,
May 21, 2008, 3:16:49 PM5/21/08
to Ruby on Rails: Talk


On May 21, 8:11 pm, mel ram <mel...@volcanicmarketing.com> wrote:
> I just installed ar-ext fromhttp://arext.rubyforge.org/svn/trunk/ar-extensions/
> and that didn't change anything. Any other ideas?
>
Seems unlikely that noting changed since your original error trace
seems highly improbable with the trunk version of the software. what's
the backtrace now ? (are you certain it's using the new code and not
picking up the old gem?)

Fred

mel ram

unread,
May 21, 2008, 3:41:11 PM5/21/08
to Ruby on Rails: Talk
HOLY CRAP!!! IT'S ALIVE!

I think it was picking up the old gem. I restarted the server and it
worked! Thank you so much!

On May 21, 12:16 pm, Frederick Cheung <frederick.che...@gmail.com>
wrote:

zdennis

unread,
May 22, 2008, 11:03:54 AM5/22/08
to Ruby on Rails: Talk
I've sent Mel a preview of ar-extensions 0.8.0 gem as well. It looks
like this fixes the issue. according to the past few messages. I will
look into pushing out an official 0.8.0 gem at or after RailsConf,

Zach Dennis
http://www.contintuousthinking.com

Norman Moore

unread,
May 22, 2008, 12:20:25 PM5/22/08
to rubyonra...@googlegroups.com
I believe that I need to do the same things you guys are discussing
here. I need to import employee records from a CSV file. Although I
have a little wrinkle in my project. Some of the employee records may
already exist, in that case I need to update some of the database
elements (hours worked, payrate, etc). I have the CSV file with headers
and my database is all setup and currently being updated manually within
a rails app. I think I am following your examples but am a little stuck
on the FasterCSV params. Can you provide me with the exact code that is
in your controller?

Thanks,
Norman Moore
--
Posted via http://www.ruby-forum.com/.

Melvin Ram

unread,
May 22, 2008, 12:28:53 PM5/22/08
to rubyonra...@googlegroups.com
Below is the code from my experimental app. It's not a production-level page. I was doing an experiment to figure out how to do this to scratch and itch.

## controller/upload.rb
class UploadController < ApplicationController
  require 'ar-extensions'

  def index   
  end

   def import_csv   
     Contact.delete_all
     if params[:dump][:dump]
        contactx = []

         FasterCSV.parse(params[:dump][:dump].read.chop, {:headers =>true,:skip_blanks => true}) do |row|
          contactx << Contact.new(
                    :first_name => row["First Name"],
                    :middle_name => row["Middle Address"],
                    :last_name => row["Last Name"],
                    :email_address => row["Email Address"],
                    :job_title => row["Job Title"],
                    :company => row["Company"],
                    :work_phone => row["Work Phone"],
                    :home_phone => row["Home Phone"],
                    :address_line_1 => row["Address Line 1"],
                    :address_line_2 => row["Address Line 2"],
                    :city => row["City"],
                    :us_state_ca_province => row["US State/CA Province"],
                    :other_state_province => row["Other State/Province"],
                    :country => row["Country"],
                    :zip_postal_code => row["Zip/Postal Code"],
                    :sub_zip_postal_code => row["Sub Zip/Postal Code"],
                    :notes => row["Notes"],
                    :custom_field_1 => row[" Custom field 1"],
                    :custom_field_2 => row[" Custom field 2"],
                    :custom_field_3 => row[" Custom field 3"],
                    :custom_field_4 => row[" Custom field 4"],
                    :custom_field_5 => row[" Custom field 5"],
                    :custom_field_6 => row[" Custom field 6"],
                    :custom_field_7 => row[" Custom field 7"],
                    :custom_field_8 => row[" Custom field 8"],
                    :custom_field_9 => row[" Custom field 9"],
                    :custom_field_10 => row[" Custom field 10"],
                    :custom_field_11 => row[" Custom field 11"],
                    :custom_field_12 => row[" Custom field 12"],
                    :custom_field_13 => row[" Custom field 13"],
                    :custom_field_14 => row[" Custom field 14"],
                    :custom_field_15 => row[" Custom field 15"]
                  )
        end

      Contact.import contactx
     

     end
    
   @contacts = Contact.find(:all)   
    respond_to do |format|
      format.html # index.html.erb
      format.xml  { render :xml => @contacts }
    end
  end

end

## view/upload/index.html.erb
<h1>Upload a data file</h1>

<% form_for :dump, :url =>{:controller=>"upload", :action=>"import_csv"},  :html => { :multipart => "true" }  do |f| -%>

    <table>
   <tr>
     <td>
      <label for="dump_file">
        Select a CSV File :
      </label>
     </td>
     <td >
       <%= f.file_field :dump -%>
     </td>
   </tr>
   <tr>
     <td colspan="2">
       <%= submit_tag "Submit" -%>
     </td>
   </tr>
 </table>
<% end -%>

## view/upload/import_csv.html.erb

<h1>Listing contacts</h1>

<table>
  <tr>
    <th>Firstname</th>
    <th>Lastname</th>
    <th>Email</th>
  </tr>

<% for contact in @contacts %>
  <tr>
    <td><%=h contact.first_name %></td>
    <td><%=h contact.last_name %></td>
    <td><%=h contact.email_address %></td>
    <td><%= link_to 'Show', contact %></td>
    <td><%= link_to 'Edit', edit_contact_path(contact) %></td>
    <td><%= link_to 'Destroy', contact, :confirm => 'Are you sure?', :method => :delete %></td>
  </tr>
<% end %>
</table>

<br />

<%= link_to 'Upload new file', :controller => :upload %>
--
~ mel

Melvin Ram
Volcanic Marketing
www.volcanicmarketing.com

Cell: 916.743.9369
Email: mel...@volcanicmarketing.com
AIM: melvinram916
MSN Messenger: melvi...@hotmail.com
Skype: melvinram

Norman Moore

unread,
May 22, 2008, 2:13:52 PM5/22/08
to rubyonra...@googlegroups.com
Melvin,

I just wanted to be able to play with a few fields to see if I could get
a few fields imported...it works perfectly! Now I know why I decided to
develop in Rails.

Thanks,
Norm

mel ram

unread,
May 22, 2008, 7:21:02 PM5/22/08
to Ruby on Rails: Talk
Yea, the community is pretty cool

On May 22, 11:13 am, Norman Moore <rails-mailing-l...@andreas-s.net>
wrote:
Reply all
Reply to author
Forward
0 new messages