I'm trying to check if a cell is empty because when the parser reaches an
empty cell it throws NoMethodError (undefined methodvalue' for
nil:NilClass)`

This is what I was trying to do:

1.upto(inventory[0].sheet_data.size) do |line|
       @projectCode = inventory[0][line][1].value unless inventory[0][line][1].value.nil?
       @ProjectName = inventory[0][line][2].value unless inventory[0][line][2].value.nil?end

also tried

1.upto(inventory[0].sheet_data.size) do |line|
       @projectCode = inventory[0][line][1].value unless inventory[0][line][1].value.empty?
       @ProjectName = inventory[0][line][2].value unless inventory[0][line][2].value.empty?
end

The cells with values have no issues, but when it reaches 2 empty rows
below all data it throws this... Can anyone tell me how to do this?

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/c2ad012f-ec23-41d6-a062-6e72c0822d1c%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Search Discussions

  • Colin Law at Oct 17, 2013 at 8:16 pm

    On 17 October 2013 19:58, Monserrat Foster wrote:
    I'm trying to check if a cell is empty because when the parser reaches an
    empty cell it throws NoMethodError (undefined methodvalue' for
    nil:NilClass)`

    This is what I was trying to do:

    1.upto(inventory[0].sheet_data.size) do |line|
    @projectCode = inventory[0][line][1].value unless
    inventory[0][line][1].value.nil?
    Is it not fairly obvious? The error message says you are calling the
    method value on something that is nil, so presumably
    inventory[0][line][1] is nil. So just test that for nil. There are
    nicer ways of coding this however, I might use
    @projectCode = inventory[0][line][1].value if inventory[0][line][1]

    However you seem to be in a loop that keeps overwriting @projectCode
    but perhaps you have snipped out some of the code.

    Colin

    --
    You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CAL%3D0gLs%2BbuY3hcYJ2u4qAvazcgb6OMX0v_2J%2BV0LEtpOHwNNVg%40mail.gmail.com.
    For more options, visit https://groups.google.com/groups/opt_out.
  • Monserrat Foster at Oct 18, 2013 at 4:38 pm
    tried
    @projectCode = inventory[0][line][1].value if inventory[0][line][1].nil?

    and even testing inventory[0][line].nil? and inventory[0].nil? and I keep
    getting the same error

    undefined method `[]' for nil:NilClass

    I am overwriting @projectCode with each iteration because there's a
    comparison later.
    On Thursday, October 17, 2013 3:45:52 PM UTC-4:30, Colin Law wrote:
    On 17 October 2013 19:58, Monserrat Foster wrote:
    I'm trying to check if a cell is empty because when the parser reaches an
    empty cell it throws NoMethodError (undefined methodvalue' for
    nil:NilClass)`

    This is what I was trying to do:

    1.upto(inventory[0].sheet_data.size) do |line|
    @projectCode = inventory[0][line][1].value unless
    inventory[0][line][1].value.nil?
    Is it not fairly obvious? The error message says you are calling the
    method value on something that is nil, so presumably
    inventory[0][line][1] is nil. So just test that for nil. There are
    nicer ways of coding this however, I might use
    @projectCode = inventory[0][line][1].value if inventory[0][line][1]

    However you seem to be in a loop that keeps overwriting @projectCode
    but perhaps you have snipped out some of the code.

    Colin
    --
    You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/c0895c4a-42e7-459c-b2d0-bf02ca166aa6%40googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
  • Colin Law at Oct 18, 2013 at 5:27 pm
    On 18 October 2013 17:38, Monserrat Foster wrote:

    Please don't top post, it makes it difficult to follow the thread.
    Insert your replies inline at appropriate points in previous message.
    Thanks.
    tried
    @projectCode = inventory[0][line][1].value if inventory[0][line][1].nil?

    and even testing inventory[0][line].nil? and inventory[0].nil? and I keep
    getting the same error

    undefined method `[]' for nil:NilClass
    if inventory[0] gives you that message then inventory must be nil.
    Put some debug code in to check out what is happening. The simplest
    way is to insert puts statements to show the values of variables. The
    output will appear in the server terminal. For more sophisticated
    debug techniques see the Rails Guide on Debugging.

    Colin
    I am overwriting @projectCode with each iteration because there's a
    comparison later.
    On Thursday, October 17, 2013 3:45:52 PM UTC-4:30, Colin Law wrote:
    On 17 October 2013 19:58, Monserrat Foster wrote:
    I'm trying to check if a cell is empty because when the parser reaches
    an
    empty cell it throws NoMethodError (undefined methodvalue' for
    nil:NilClass)`

    This is what I was trying to do:

    1.upto(inventory[0].sheet_data.size) do |line|
    @projectCode = inventory[0][line][1].value unless
    inventory[0][line][1].value.nil?
    Is it not fairly obvious? The error message says you are calling the
    method value on something that is nil, so presumably
    inventory[0][line][1] is nil. So just test that for nil. There are
    nicer ways of coding this however, I might use
    @projectCode = inventory[0][line][1].value if inventory[0][line][1]

    However you seem to be in a loop that keeps overwriting @projectCode
    but perhaps you have snipped out some of the code.

    Colin
    --
    You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CAL%3D0gLuhPRs26J7EKddCriFRL3_4KYnELjCRoMHTUFuxOyHm5g%40mail.gmail.com.
    For more options, visit https://groups.google.com/groups/opt_out.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouprubyonrails-talk @
categoriesrubyonrails
postedOct 17, '13 at 6:58p
activeOct 18, '13 at 5:27p
posts4
users2
websiterubyonrails.org
irc#RubyOnRails

2 users in discussion

Colin Law: 2 posts Monserrat Foster: 2 posts

People

Translate

site design / logo © 2021 Grokbase