undefined method `gsub' for nil:NilClass
bilalmajeed-zz opened this issue · 4 comments
I followed the steps to get this up but I am getting the error
"undefined method `gsub' for nil:NilClass"
I've looked at the old closed issues but they seem to be no help, so I decided to ask u guy directly
Here is my setup
config/initializers/carrierwave.rb
CarrierWave.configure do |config|
config.dropbox_app_key = ENV["APP_KEY"]
config.dropbox_app_secret = ENV["APP_SECRET"]
config.dropbox_access_token = ENV["ACCESS_TOKEN"]
config.dropbox_access_token_secret = ENV["ACCESS_TOKEN_SECRET"]
config.dropbox_user_id = ENV["USER_ID"]
config.dropbox_access_type = "app_folder"
config.cache_dir = "#{Rails.root}/tmp/uploads"
end
/app/uploaders/avatar_uploader.rb
class AvatarUploader < CarrierWave::Uploader::Base
include CarrierWave::MiniMagick
storage :dropbox
def store_dir
"profile_pics/"
end
process :resize_to_fit => [150, 150]
def extension_white_list
%w(jpg jpeg gif png)
end
end
My controller
class ClassmatesController < ApplicationController
def index
@showNav = true
@classmates = Classmate.all
end
def create
@showNav = true
@classmate = Classmate.new(params[:classmate])
@classmate.avatar = params[:file]
name = @classmate.name
github = @classmate.githubProfile
site = @classmate.website
@classmate.githubProfile = ((github.split('//')[-1]).split('www.')[-1]).split('/')[-1]
@classmate.website = ((site.split('//')[-1]).split('www.')[-1])
respond_to do |format|
if @classmate.save
format.html { redirect_to action: "index"}
format.json { render json: @classmate, status: :created, location: @classmate }
else
format.html { render action: "new" }
format.json { render json: @classmate.errors, status: :unprocessable_entity }
end
end
end
end
And the code is showing me that is it failing at:
if @classmates.save
Please let me know anything I have been doing wrong, but I cant seem to fix this problem.
Thanks
Hi @bilalmajeed!
Did you set the environment variables to their proper value ? ENV
is going to look at environment variables defined by your shell so you need to set their values somewhere.
Actually, this piece of code use environment variables because it's a wrong practice to store credentials as-is inside your configuration files but now you can rely on the config/secrets.yml
feature to store them ; it didn't exist in the default Rails stack when it was written, the README should be updated.
thanks so much for the quick reply...i fixed it
No problem! :-)