I used the following guide: http://www.tweetegy.com/2012/10/setting-up-a-captcha-with-recaptcha-service-and-the-captcha-gem/
I have the following in development.rb:
ENV['RECAPTCHA_PUBLIC_KEY'] = 'keyString'
ENV['RECAPTCHA_PRIVATE_KEY'] = 'keyString'
In config/initializers/recaptcha.rb:
Recaptcha.configure do |config|
config.public_key = RECAPTCHA_PUBLIC_KEY
config.private_key = RECAPTCHA_PRIVATE_KEY
end
I get the following error when I run rails server in development:
Exiting
/home/action/visualhaggard.org/config/initializers/recaptcha.rb:2:in `block in <top (required)>': uninitialized constant RECAPTCHA_PUBLIC_KEY (Nam
eError)
Has anyone encountered and solved this problem? Do I have a typo? Thanks.
The example doesn't define the RECAPTCHA_PUBLIC_KEY in an environment variable. It just defines it as a constant.
#put this in development.rb and in production.rb (separate keys in each so you can test!)
RECAPTCHA_PUBLIC_KEY= 'your-public-key'
RECAPTCHA_PRIVATE_KEY= 'your-private-key'
Related
I'm upgrading from 4.2.3 to 5.2.2.
https://guides.rubyonrails.org/upgrading_ruby_on_rails.html#new-framework-defaults
Where do I put these new defaults? I tried to put them in config/initializers/config.rb but it said
C:/Users/Chloe/workspace/app/config/initializers/config.rb:38:in 'block in ': undefined method 'active_record' for Config:Module (NoMethodError)
I saw a new file file config/initializers/new_framework_defaults_5_2.rb and saw that config/environments/development.rb starts with Rails.application.configure do and has lines like config.active_record.migration_error so I added the following to new_framework_defaults_5_2.rb
Rails.application.configure do |config|
config.active_record.belongs_to_required_by_default = true
config.action_controller.per_form_csrf_tokens = true
...
But it said
C:/Users/Chloe/workspace/app/config/initializers/new_framework_defaults_5_2.rb:43:in 'block in ': undefined method 'active_record' for # (NoMethodError)
So where do I put them?
I have been deploying rails 4.1 application with capistrano 3. it has been working fine. but
when i tried to do rake tasks (uncommenting require 'capistrano/rails/assets'). i get this error
cap aborted!
SSHKit::Runner::ExecuteError: Exception while executing on host xxx.xxx.xxx.xxx: rake exit status: 1
rake stdout: Nothing written
rake stderr: config.eager_load is set to nil. Please update your config/environments/*.rb files accordingly:
* development - set it to false
* test - set it to false (unless you use a tool that preloads your test environment)
* production - set it to true
rake aborted!
ArgumentError: Missing required arguments: google_storage_access_key_id, google_storage_secret_access_key
/home/deploy/yelo/shared/bundle/ruby/2.1.0/gems/fog-core-1.24.0/lib/fog/core/service.rb:237:in `validate_options'
/home/deploy/yelo/shared/bundle/ruby/2.1.0/gems/fog-core-1.24.0/lib/fog/core/service.rb:261:in `handle_settings'
/home/deploy/yelo/shared/bundle/ruby/2.1.0/gems/fog-core-1.24.0/lib/fog/core/service.rb:98:in `new'
/home/deploy/yelo/shared/bundle/ruby/2.1.0/gems/fog-core-1.24.0/lib/fog/storage.rb:26:in `new'
/home/deploy/yelo/shared/bundle/ruby/2.1.0/gems/carrierwave-0.10.0/lib/carrierwave/uploader/configuration.rb:83:in `eager_load_fog'
/home/deploy/yelo/shared/bundle/ruby/2.1.0/gems/carrierwave-0.10.0/lib/carrierwave/uploader/configuration.rb:96:in `fog_credentials='
/home/deploy/yelo/releases/20140910131617/config/initializers/carrierwave.rb:8:in `block in <top (required)>'
/home/deploy/yelo/shared/bundle/ruby/2.1.0/gems/carrierwave-0.10.0/lib/carrierwave/uploader/configuration.rb:118:in `configure'
/home/deploy/yelo/shared/bundle/ruby/2.1.0/gems/carrierwave-0.10.0/lib/carrierwave.rb:14:in `configure'
/home/deploy/yelo/releases/20140910131617/config/initializers/carrierwave.rb:5:in `<top (required)>'
/home/deploy/yelo/shared/bundle/ruby/2.1.0/gems/activesupport-4.1.4/lib/active_support/dependencies.rb:241:in `load'
/home/deploy/yelo/shared/bundle/ruby/2.1.0/gems/activesupport-4.1.4/lib/active_support/dependencies.rb:241:in `block in load'
the config.eager_load is set to true. the thing with google_storage_access_key_id the keys are initialized inside a initializer with values config.secrets.yml
require 'fog'
require 'rails'
require 'carrierwave'
CarrierWave.configure do |config|
config.root = Rails.root.join('tmp')
config.cache_dir = 'carrierwave'
config.fog_credentials = {
:provider => 'Google',
:google_storage_access_key_id => Rails.application.secrets.storage_access_key,
:google_storage_secret_access_key => Rails.application.secrets.storage_access_secret
}
config.fog_directory = 'yelostore'
end
config.secrets.yml
storage_access_key: <%= ENV['STORAGE_ACCESS_KEY']%>
storage_access_secret: <%= ENV['STORAGE_ACCESS_SECRET']%>
i stored my environmental variables in /etc/profile.
there issues arise only if i do some rake or execute tasks.
if i removed the initializer file i get another error
Devise.secret_key was not set. Please add the following to your Devise initializer:
config.secret_key = '6b88a299ed1361b5c0275e.....'
this is essentiall because of secret_key_base: <%= ENV["SECRET_KEY_BASE"] %> not getting loaded at that point.
Finally i can run all tasks i go to the root path. only while doing it through capistarno these errors arise. as capistarno not getting the config.scecrets env variables which is stored in /etc/profile
capistrano seems like to look into environmental variables from /etc/environment rather than shell so bashrc or profile didnt't work.
The config.eager_load issue was solved after i upgraded to capistrano 3.0rc to 3.2
The Error has nothing to do with the secret_key_base.
In the file config/initializers/devise.rb add the config.secret_key='6b88...' within the setup block:
Devise.setup do |config|
config.secret_key = '6b88a299ed1361b5c0275e...'
...
end
I updated a Rails 2.3 app to 3.2 and it seemed to be a pretty simple process but when setting up the Figaro gem I came across this error:
C:\Sites\JustManage>rails generate figaro:install
C:/Sites/JustManage/config/environment.rb:5:in `<top (required)>': uninitialized
constant Projectmanagement (NameError)
from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/railties-3.2.1
/lib/rails/application.rb:103:in `require_environment!'
from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/railties-3.2.1
/lib/rails/commands.rb:25:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'
Here is what my environment.rb looks like:
# Load the rails application
require File.expand_path('../application', __FILE__)
# Initialize the rails application
Projectmanagement::Application.initialize!
Here is my application.rb file:
require File.expand_path('../application', __FILE__)
require 'rails/all'
if defined?(Bundler)
Bundler.require(*Rails.groups(:assets => %w(development test)))
end
module Railsapp
class Application < Rails::Application
config.encoding = "utf-8"
config.filter_parameters += [
:password,
:password_clear,
:password_verify
]
config.assets.enabled = true
config.assets.version = '1.0'
end
end
I've never run into this error before and don't know why it's happening.
It seems like the name of your application is not the same in the different places it needs to appear in. Check the following files and see if they contain either Projectmanagement::Application or Railsapp::Application:
config/application.rb (Actually initializes the constant)
config/environment.rb
config/environments/development.rb
config/environments/production.rb
config/environments/test.rb
config/initializers/secret_token.rb
config/initializers/session_store.rb
config/mongoid.yml (if using Mongoid)
config/routes.rb
config.ru
Rakefile
app/views/layouts/application.html.erb, in title tag
Then pick a name (either Projectmanagement or Railsapp) and change all the names in the above files so they match. That should resolve the uninitialized constant error you are having.
I can't be certain that they are not errors from copy/pasting, but your application.rb appears to be incorrect. Issues I see:
L1: You are requiring application.rb a second time where you mean to be requiring boot.rb.
L12: The name of this module (i.e. the name of your app) is not consistent here with what is in your environment.rb file (Railsapp vs. Projectmanagement).
The second issue is actually causing the error you are seeing - you have not defined the Projectmanagement constant before calling a method on it.
I am newbie in Ruby. I installed by following this tutorial: http://udooz.net/blog/2011/02/facebook-app-using-rails-koala/
Now, when I do this: rails generate controller
rails generate controller home index
I get this error:
/home/hiccup-pro/Documents/qstack/config/environment.rb:8:in `<top (required)>': undefined local variable or method `config' for main:Object (NameError)
from /home/hiccup-pro/.rvm/gems/ruby-1.9.2-p320/gems/railties-3.2.3/lib/rails/application.rb:103:in `require'
from /home/hiccup-pro/.rvm/gems/ruby-1.9.2-p320/gems/railties-3.2.3/lib/rails/application.rb:103:in `require_environment!'
from /home/hiccup-pro/.rvm/gems/ruby-1.9.2-p320/gems/railties-3.2.3/lib/rails/commands.rb:25:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'
I fixed it. Atleast that bug, but now I've a different bug and that is: uninitialized constant LoginController. I googled a bit and found out that I should not mention config.* in the environment.rb.
Anyway,
this is my environment.rb
# Load the rails application
require File.expand_path('../application', __FILE__)
# Initialize the rails application
Qack::Application.initialize!
config.action_controller.allow_forgery_protection = false
So, why do I get this uninitialized constant LoginController error?
Without seeing your environment.rb is hard to say, but my best shoot is that you put the code
config.action_controller.allow_forgery_protection = false
config.gem "koala"
Outside of the block
Rails::Initializer.run do |config|
....
end
That is inside of environment.rb. If there is no such a block add it like this:
Rails::Initializer.run do |config|
config.action_controller.allow_forgery_protection = false
config.gem "koala"
end
I am trying to get Carrierwave (0.5.1) to work with Mongoid (2.0.0.beta.20), Rails 3. I followed every step at this guide.
In config/initializers/carrierwave.rb, I have:
CarrierWave.configure do |config|
config.grid_fs_database = Mongoid.database.name
config.grid_fs_host = Mongoid.config.master.connection.host
config.storage = :grid_fs
config.grid_fs_access_url = "/uploads"
end
When I try to start my server (rails server). In the console, I get:
...config/initializers/carrierwave.rb:3:in `block in <top
(required)>': undefined method `host' for #<Mongo::Connection:
0x00000103802420> (NoMethodError)
I don't understand why I am getting this error. I've looked everywhere
and can't seem to locate why this is happening...
It seems, Mongoid.config.master.connection.host doesn't work anymore
in newer versions of Mongoid. Was this removed? What is the
replacement for this?
So far my workaround is the following code:
CarrierWave.configure do |config|
config.grid_fs_database = Mongoid.database.name
config.grid_fs_host = 'localhost'
config.storage = :grid_fs
config.grid_fs_access_url = "/uploads"
end
Line 3, should be: config.grid_fs_host = 'localhost'. <-- Is there a better way to dynamically indicate the host depending on environment?
Found out that the mongo gem has changed. So it now has to be:
config.grid_fs_host = Mongoid.database.connection.primary_pool.host