Search code examples
rubyruby-on-rails-3nullrake-task

ROR + Error For nil:NilClass In Rake Task


In my Rake Command I am calling XML to retrieve data. If person_id is valid, then it saved. But I am getting error.

if [email protected]_id.nil?
    @project.team_members << @person
 end

Error :: rake aborted! undefined method `team_members' for nil:NilClass

Please Suggest Some Thing !!!


Solution

  • @project is a nil variable and this is why you cannot invoke team_members. Check how you define it. Moreover, you may want to follow the ruby way of doing things. 'If not' occasions are better to write like :

    unless @case.person_id.nil?
      ...