No Implicit Conversion of Nil into String

no implicit conversion of nil into String error

One of (or more) values in string

finalStatsFile.puts col_date+", "+col_constant1+", "+ col_appYear+", "+col_statsDesc+", "+col_constant2+", "+col_keyStats+", "+col_weeklyTotal

became nil. To fix the output you should explicitly cast them to strings:

finalStatsFile.puts col_date.to_s + ", " + 
col_constant1.to_s + ", " +
col_appYear.to_s + ", " +
col_statsDesc.to_s + ", " +
col_constant2.to_s + ", " +
col_keyStats.to_s + ", " +
col_weeklyTotal.to_s

BTW, the whole clause might be rewritten in more rubyish manner:

finalStatsFile.puts [ col_date,
col_constant1,
col_appYear,
col_statsDesc,
col_constant2,
col_keyStats,
col_weeklyTotal ].map(&:to_s).join(', ')

Rails: no implicit conversion of nil into String

It's occurring because you have a nil position on your arrays, try this

whitelist_start = self.domain.whitelists.map(&:url_start).compact
whitelist_end = self.domain.whitelists.map(&:url_end).compact

I will show you, your array is not empty

2.3.1 :017 > test = []
=> []
2.3.1 :019 > "string".starts_with?(*test)
=> false

And now, your nil array position

2.3.1 :020 > test = [nil]
=> [nil]
2.3.1 :021 > "string".starts_with?(*test)
TypeError: no implicit conversion of nil into String

In my tests, this error occur only when nil is in the first position

no implicit conversion of nil into String Ruby on Rails

This is because you are using + to implicitly concatenate the URL to your host, but at least for one post, @post.preview_image.try(:data).try(:url) is returning as nil.

You could fix it by using string interpolation like this:

%meta{:content => "https://www.joynus.com#{@post.preview_image.try(:data).try(:url)}", :name => "twitter:image"}

Or by explicitly converting to string with to_s like this:

%meta{:content => "https://www.joynus.com"+@post.preview_image.try(:data).try(:url).to_s, :name => "twitter:image"}

# TypeError: no implicit conversion of nil into String for jwt encoding environment

Looks like you have issue with your configuration of ENV["jwt_secret"]. Let us first try it by hard coding values replace JWT.encode(payload, ENV["jwt_secret"]) with following line

JWT.encode(payload, "your_secret_key_anything_text")

Now try, if it works, that mean you have issue in your configuration file and it is not getting your secret key. Now let us resolve issue. Let us try some solution. If you have .env already setup and working with configurations, than just add following line

JWT_SECRET='yoursecretkey'
  1. add following gem in your Gemfile
gem 'dotenv-rails'

No use bundle install to install this Gem, You have to specify ENV["jwt_secret"] in your .env file.

JWT_SECRET='yoursecretkey'

in Rails 5.2 you can use EDITOR=vim rails credentials:edit to add this variable in secrets too, which whole process is little bit complicated to suggest to check documentation.

dealing with a file path argument: no implicit conversion of nil into String

When your guard conditions are triggered, you need to stop further processing (no need to check for readability of a file at file_path if you already established that file_path is nil). It could look like this, for example:

def initialize(log_file_path = nil)
unless log_file_path
puts 'please add log file path'
return
end
unless File.exist?(log_file_path)
puts 'Could not find the file path'
return
end
unless File.readable?(log_file_path)
puts '${log_file_path} is unreadable'
return
end

extract_log_file(log_file_path)
end

TypeError (no implicit conversion of nil into String) Rails devise-jwt gem on Production environment

Seems, I missed gem 'dotenv-rails' in production block

Fixed with just two steps.

gem 'dotenv-rails', :groups => [:development, :test, :production]

add

set :linked_files, fetch(:linked_files, []).push('config/database.yml', '.env')


Related Topics



Leave a reply



Submit