I am a beginner with ruby, i tried to use lightcsv but i have a problem
when i use a .csv file
ERROR
···
-------------------------------------------
/file2.rb:114:in `title=': undefined method `[]=' for nil:NilClass
(NoMethodError)
from file1.rb:19:in `publish_post'
from file1.rb:51
from /Library/Ruby/Gems/1.8/gems/lightcsv-0.2.2/lib/lightcsv.rb:142:in
`each'
from /Library/Ruby/Gems/1.8/gems/lightcsv-0.2.2/lib/lightcsv.rb:51:in
`foreach'
from /Library/Ruby/Gems/1.8/gems/lightcsv-0.2.2/lib/lightcsv.rb:82:in
`call'
from /Library/Ruby/Gems/1.8/gems/lightcsv-0.2.2/lib/lightcsv.rb:82:in
`open'
from /Library/Ruby/Gems/1.8/gems/lightcsv-0.2.2/lib/lightcsv.rb:50:in
`foreach'
from file1.rb:48
-------------------------------------------
files concerned:
file1.rb
-------------------------------------------
LightCsv.foreach(config) do|row|
begin
post = MyClass.new(row[0], row[1], row[2])
[...]
end
end
-------------------------------------------
file2.rb
-------------------------------------------
if real.is_a? String
[...]
else
define_method("#{key}=") do |value| @form[real] = value
end
end
-------------------------------------------
if i replace row in file1.rb by row = [data1, data2, data3] it works
That's trying to tell you that at line 114 in file2.rb, you're
assinging to a subscrip of something (i.e., trying to set an element
in it by using square brackets), but that something is nil. Probably
it's somewhere where you think you have an array or a hash. If line
114 is where you do "@form[real] = value" then that probably means
that @form is nil. Take a look at the code that's supposed to set @form (and if that's not a Rails controller, possibly also the code
that's supposed to call that code). Then if you can't understand why
it's wrong, put it somewhere we can get to, post a link, and we'll try
to help you figure it out.
-Dave
···
On Fri, Jan 13, 2012 at 13:17, thomas carlier <carlier.thomas@gmail.com> wrote:
/file2.rb:114:in `title=': undefined method `=' for nil:NilClass
(NoMethodError)
--
Dave Aronson, President, Dave Aronson Software Engineering and Training
Ruby on Rails Freelancing (Northern Virginia, Washington DC, or Remote)
DaveAronson.com, Codosaur.us, Dare2XL.com, & RecruitingRants.com (NEW!)
Specialization is for insects. (Heinlein) - Have Pun, Will Babble! (me)
The backtrace shows the line number where the exception was raised.
If you send the whole code attached would be easier to help you debug it.
By the fragments you sent the only thing I can infer is...
you are trying to use the = on a nil object.
Abinoam Jr.
···
On Fri, Jan 13, 2012 at 2:17 PM, thomas carlier <carlier.thomas@gmail.com> wrote:
Hi,
I am a beginner with ruby, i tried to use lightcsv but i have a problem
when i use a .csv file
ERROR
-------------------------------------------
/file2.rb:114:in `title=': undefined method `=' for nil:NilClass
(NoMethodError)
from file1.rb:19:in `publish_post'
from file1.rb:51
from /Library/Ruby/Gems/1.8/gems/lightcsv-0.2.2/lib/lightcsv.rb:142:in
`each'
from /Library/Ruby/Gems/1.8/gems/lightcsv-0.2.2/lib/lightcsv.rb:51:in
`foreach'
from /Library/Ruby/Gems/1.8/gems/lightcsv-0.2.2/lib/lightcsv.rb:82:in
`call'
from /Library/Ruby/Gems/1.8/gems/lightcsv-0.2.2/lib/lightcsv.rb:82:in
`open'
from /Library/Ruby/Gems/1.8/gems/lightcsv-0.2.2/lib/lightcsv.rb:50:in
`foreach'
from file1.rb:48
-------------------------------------------
files concerned:
file1.rb
-------------------------------------------
LightCsv.foreach(config) do|row|
begin
post = MyClass.new(row[0], row[1], row[2])
[...]
end
end
-------------------------------------------
file2.rb
-------------------------------------------
if real.is_a? String
[...]
else
define_method("#{key}=") do |value| @form[real] = value
end
end
-------------------------------------------
if i replace row in file1.rb by row = [data1, data2, data3] it works
I don't understand *when* you're having a problem. Please answer
these questions separately and simply, so that we can get a solid
handle on that.
1) When is @form nil: when you use the row (as in the first example),
or when you use literal values (as in the second example), or both?
2) Assuming it's not both, then does the code do what you want, in the
*other* case?
3) Have you looked at what you're actually getting in "row"? How does
it differ from what you pass as literal values? Does there seem to be
any pattern to the difference? Can you post a CSV file (fake so you
don't reveal passwords), along with what you get from the CSV parser
running on the same file?
-Dave
···
On Fri, Jan 13, 2012 at 21:18, thomas carlier <carlier.thomas@gmail.com> wrote:
That's the problem, when i use the .csv file @form=nil
if i replace the line
post = WordpressSite.new(row[0], row[1], row[2])
by
post = WordpressSite.new("http://example.com", "user", "password")
that's why i don't understand my mistake
--
Dave Aronson, President, Dave Aronson Software Engineering and Training
Ruby on Rails Freelancing (Northern Virginia, Washington DC, or Remote)
DaveAronson.com, Codosaur.us, Dare2XL.com, & RecruitingRants.com (NEW!)
Specialization is for insects. (Heinlein) - Have Pun, Will Babble! (me)