Reputation: 28920
I am having some issues correctly formatting the code below following Rubocop inspection in my Ruby on Rails Application. I keep getting the errors:
Rubocop:Literal[:success, JSON.parse(response.to_str)] used in void context.[Lint/Void]
and
Rubocop:Literal[:unprocessable_entity, JSON.parse(response.to_str)] used in void context.[Lint/Void].
I just can't figure out what the issue is with the code and how to fix it.
case response.code
when 200
[:success, JSON.parse(response.to_str)]
redirect_to root_url, notice: 'Logged in!'
when 422
[:unprocessable_entity, JSON.parse(response.to_str)]
flash.now[:alert] = 'Email or password is invalid'
render 'new'
else
raise "Invalid response #{response.to_str} received."
end
Upvotes: 0
Views: 769
Reputation: 1267
You are not using this [:success, JSON.parse(response.to_str)]
and this [:unprocessable_entity, JSON.parse(response.to_str)]
anywhere in your code. Either remove it or assign it in a variable but assigning it in a variable and not using that variable may cause the warning again.
You should remove the code which you are not using. Try this:
case response.code
when 200
redirect_to root_url, notice: 'Logged in!'
when 422
flash.now[:alert] = 'Email or password is invalid'
render 'new'
else
raise "Invalid response #{response.to_str} received."
end
or try this:
case response.code
when 200
@success = [:success, JSON.parse(response.to_str)]
redirect_to root_url, notice: 'Logged in!'
when 422
@error = [:unprocessable_entity, JSON.parse(response.to_str)]
flash.now[:alert] = 'Email or password is invalid'
render 'new'
else
raise "Invalid response #{response.to_str} received."
end
Let me know if it worked.
Upvotes: 1