mardi 7 novembre 2017

Rspec Testing : NoMethodError - undefined method 'id' for nil.Nilclass

When I am running rspec testing for a controller in Rails, I get the error "NoMethodError : undefined method 'id' for nil.Nilclass" at the second line.

params[:tag_id] is passed down from the front end, so I can't initialize that. How would I correct this error?

     #enables the id to be a name rather than just a number
    if (params[:tag_id].class) == String && (params[:tag_id]!= "alltags")
       tag_id = Tag.find_by(name: params[:tag_id]).id
    elsif params[:tag_id] == "alltags"
       tag_id = "alltags"
    else
       tag_id = params[:tag_id]
    end

Aucun commentaire:

Enregistrer un commentaire