I have created an app on dropbox and I am following the https://github.com/robin850/carrierwave-dropbox steps but cannot get the access token.
It has 400 bad request although I am providing correct key and app secret but cannot get the link to allow my app.
Here is the error and I am creating a ruby-on-rails app:
rake aborted!
DropboxAuthError: Error getting request token. Is your app key and secret correctly set? Server returned 400: Bad Request.
/var/lib/gems/2.3.0/gems/dropbox-sdk-1.6.5/lib/dropbox_sdk.rb:277:in `get_token'
/var/lib/gems/2.3.0/gems/dropbox-sdk-1.6.5/lib/dropbox_sdk.rb:293:in `get_request_token'
/var/lib/gems/2.3.0/gems/dropbox-sdk-1.6.5/lib/dropbox_sdk.rb:299:in `get_authorize_url'
/var/lib/gems/2.3.0/gems/carrierwave-dropbox-1.2.1/lib/carrierwave/dropbox/rake.rb:13:in `authorize'
/var/lib/gems/2.3.0/gems/carrierwave-dropbox-1.2.1/lib/carrierwave/dropbox/authorize.rake:11:in `block (2 levels) in <top (required)>'
/var/lib/gems/2.3.0/gems/rake-12.1.0/exe/rake:27:in `<top (required)>'
Tasks: TOP => dropbox:authorize
(See full trace by running task with --trace)
Have you configured carrierwave
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 = "dropbox"
end
Here is an example hope it can work:
1- create a file config/config.yml and provide here your keys:
default: &default
development:
<<: *default
app_key: "your_app_key"
production: &production
<<: *default
app_key: "your_app_key"
staging: &staging
<<: *default
app_key: "your_app_key"
2 - in environment.rb file
# Load the Rails application.
require_relative 'application'
APP_CONFIG = YAML.load_file("#{Rails.root}/config/config.yml")[Rails.env]
# Initialize the Rails application.
Rails.application.initialize!
3 - then you can use in in carrierwave.rb file
CarrierWave.configure do |config|
config.dropbox_app_key = APP_CONFIG['app_key']
//and your another configuration so on...
}
end
if you have right api keys permission then it should work. thanks
Related
I have a project with Rails 5.2.4.5. Where I am using Rspec for testing, and Postgres as database.
RSpec 3.10
- rspec-core 3.10.1
- rspec-expectations 3.10.1
- rspec-mocks 3.10.2
- rspec-support 3.10.2
When I run rails spec:helpers I am getting the following error:
An error occurred while loading ./spec/helpers/pluralize_without_count_helper_spec.rb.
Failure/Error: ActiveRecord::Migration.maintain_test_schema!
ActiveRecord::NoDatabaseError:
FATAL: database "jmschp" does not exist
# ./spec/rails_helper.rb:30:in `<top (required)>'
# ./spec/helpers/pluralize_without_count_helper_spec.rb:1:in `<top (required)>'
# ------------------
# --- Caused by: ---
# PG::ConnectionBad:
# FATAL: database "jmschp" does not exist
# ./spec/rails_helper.rb:30:in `<top (required)>'
No examples found.
I have droped the data base and recreated it again.
In my database.yml I have:
default: &default
adapter: postgresql
encoding: unicode
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 6 } %>
development:
<<: *default
url: <%= ENV['DATABASE_URL'] %>
database: store_development
test:
<<: *default
url: <%= ENV['TEST_DATABASE_URL'] %>
In development work fine.
How can I fix this?
I don't see the name of the test database setup in database.yml you can try below
test:
<<: *default
database: <%= ENV['TEST_DATABASE_URL'] || 'store_development_test' %>
and run this to make sure test database has all the migrations applied.
bin/rails db:test:prepare
Recently we started migrating our codebase from rails 5 to rails 6. Everything seems to work fine except sidekiq. Whenever we tried to run sidekiq in production mode it always throws an error database configuration does not specify adapter. I am pretty sure that we have mentioned an adapter in database.yml. Can someone please help to resolve this issue?
For reference
Rails 6.0.3.4
Sidekiq 6.1.2
Ruby 2.7.1p83
databsae.yml file
default: &default
adapter: postgresql
pool: <%= ENV['DATABASE_POOL'] %>
timeout: 5000
database: anajmandi
development:
primary:
<<: *default
url: <%= ENV['DATABASE_URL'] %>
multidb:
fallback: true
follower:
<<: *default
url: <%= ENV['DATABASE_SLAVE_URL'] %>
replica: true
multidb:
fallback: true
test:
<<: *default
database: db/test.sqlite3
production:
primary:
<<: *default
url: <%= ENV['DATABASE_URL'] %>
multidb:
fallback: true
follower:
<<: *default
url: <%= ENV['DATABASE_SLAVE_URL'] %>
replica: true
multidb:
fallback: true
and sidekiq.rb file
# typed: strict
if Rails.env.production?
# three unicorns = 3 connections
Sidekiq.configure_client do |config|
config.redis = { :size => 1 }
end
Sidekiq.configure_server do |config|
config.redis = { url: ENV['REDIS_URL'], size: 22 }
Rails.application.config.after_initialize do
Rails.logger.info("DB Connection Pool size for Sidekiq Server before disconnect is: #{ActiveRecord::Base.connection.pool.instance_variable_get('#size')}")
ActiveRecord::Base.connection_pool.disconnect!
ActiveSupport.on_load(:active_record) do
config = Rails.application.config.database_configuration[Rails.env]
config['reaping_frequency'] = ENV['DATABASE_REAP_FREQ'] || 10 # seconds
config['pool'] = ENV['WORKER_DB_POOL_SIZE'] || Sidekiq.options[:concurrency]
ActiveRecord::Base.establish_connection(config)
Rails.logger.info("DB Connection Pool size for Sidekiq Server is now: #{ActiveRecord::Base.connection.pool.instance_variable_get('#size')}")
end
end
end
end
and this is the error stack trace on running command bundle exec sidekiq -e production -C config/sidekiq.yml
DB Connection Pool size for Sidekiq Server before disconnect is: 5
database configuration does not specify adapter
/Users/yadusingla/.rvm/gems/ruby-2.7.1/gems/activerecord-6.0.3.4/lib/active_record/connection_adapters/connection_specification.rb:161:in `spec'
/Users/yadusingla/.rvm/gems/ruby-2.7.1/gems/activerecord-6.0.3.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:1052:in `establish_connection'
/Users/yadusingla/.rvm/gems/ruby-2.7.1/gems/activerecord-6.0.3.4/lib/active_record/connection_handling.rb:51:in `establish_connection'
/Users/yadusingla/.rvm/gems/ruby-2.7.1/gems/activerecord-import-1.0.6/lib/activerecord-import/import.rb:250:in `establish_connection'
/Users/yadusingla/spars/procol-backend/config/initializers/sidekiq.rb:19:in `block (3 levels) in <top (required)>'
/Users/yadusingla/.rvm/gems/ruby-2.7.1/gems/activesupport-6.0.3.4/lib/active_support/lazy_load_hooks.rb:71:in `class_eval'
/Users/yadusingla/.rvm/gems/ruby-2.7.1/gems/activesupport-6.0.3.4/lib/active_support/lazy_load_hooks.rb:71:in `block in execute_hook'
/Users/yadusingla/.rvm/gems/ruby-2.7.1/gems/activesupport-6.0.3.4/lib/active_support/lazy_load_hooks.rb:61:in `with_execution_control'
/Users/yadusingla/.rvm/gems/ruby-2.7.1/gems/activesupport-6.0.3.4/lib/active_support/lazy_load_hooks.rb:66:in `execute_hook'
/Users/yadusingla/.rvm/gems/ruby-2.7.1/gems/activesupport-6.0.3.4/lib/active_support/lazy_load_hooks.rb:43:in `block in on_load'
/Users/yadusingla/.rvm/gems/ruby-2.7.1/gems/activesupport-6.0.3.4/lib/active_support/lazy_load_hooks.rb:42:in `each'
/Users/yadusingla/.rvm/gems/ruby-2.7.1/gems/activesupport-6.0.3.4/lib/active_support/lazy_load_hooks.rb:42:in `on_load'
Here I am using a 3-tier configuration, so for 3 tier configuration initializer isn't correctly defined. If we select configurations by environment variable then we'll get two, both primary and follower. Rails don't know which one to access so the app has to select the right one.
Change config = Rails.application.config.database_configuration[Rails.env] to
self.configurations = Rails.application.config.database_configuration
config = configurations.configs_for(env_name: Rails.env, spec_name: "primary").config
Refer to this link https://github.com/rails/rails/issues/40640
I cannot figure out why I am constantly getting this error when running rake db:migrate:status after switching over to Postgresql and Rails 5.2.1
[root:7e2d33988106:~/myapp]# rake db:migrate:status 12:04AM/06.27
rake aborted!
PG::ConnectionBad: fe_sendauth: no password supplied
/usr/local/rvm/gems/ruby-2.5.1/gems/pg-1.1.4/lib/pg.rb:56:in `initialize'
/usr/local/rvm/gems/ruby-2.5.1/gems/pg-1.1.4/lib/pg.rb:56:in `new'
/usr/local/rvm/gems/ruby-2.5.1/gems/pg-1.1.4/lib/pg.rb:56:in `connect'
/usr/local/rvm/gems/ruby-2.5.1/gems/activerecord-5.2.3/lib/active_record/connection_adapters/postgresql_adapter.rb:692:in `connect'
/usr/local/rvm/gems/ruby-2.5.1/gems/activerecord-5.2.3/lib/active_record/connection_adapters/postgresql_adapter.rb:223:in `initialize'
/usr/local/rvm/gems/ruby-2.5.1/gems/activerecord-5.2.3/lib/active_record/connection_adapters/postgresql_adapter.rb:48:in `new'
/usr/local/rvm/gems/ruby-2.5.1/gems/activerecord-5.2.3/lib/active_record/connection_adapters/postgresql_adapter.rb:48:in `postgresql_connection'
/usr/local/rvm/gems/ruby-2.5.1/gems/activerecord-5.2.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:811:in `new_connection'
/usr/local/rvm/gems/ruby-2.5.1/gems/activerecord-5.2.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:855:in `checkout_new_connection'
/usr/local/rvm/gems/ruby-2.5.1/gems/activerecord-5.2.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:834:in `try_to_checkout_new_connection'
/usr/local/rvm/gems/ruby-2.5.1/gems/activerecord-5.2.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:795:in `acquire_connection'
/usr/local/rvm/gems/ruby-2.5.1/gems/activerecord-5.2.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:523:in `checkout'
/usr/local/rvm/gems/ruby-2.5.1/gems/activerecord-5.2.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:382:in `connection'
/usr/local/rvm/gems/ruby-2.5.1/gems/activerecord-5.2.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:1014:in `retrieve_connection'
/usr/local/rvm/gems/ruby-2.5.1/gems/activerecord-5.2.3/lib/active_record/connection_handling.rb:118:in `retrieve_connection'
/usr/local/rvm/gems/ruby-2.5.1/gems/activerecord-5.2.3/lib/active_record/connection_handling.rb:90:in `connection'
/usr/local/rvm/gems/ruby-2.5.1/gems/activerecord-5.2.3/lib/active_record/schema_migration.rb:22:in `table_exists?'
/usr/local/rvm/gems/ruby-2.5.1/gems/activerecord-5.2.3/lib/active_record/railties/databases.rake:124:in `block (3 levels) in <top (required)>'
/usr/local/rvm/gems/ruby-2.5.1/gems/rake-12.3.2/exe/rake:27:in `<top (required)>'
/usr/local/rvm/gems/ruby-2.5.1/bin/ruby_executable_hooks:24:in `eval'
/usr/local/rvm/gems/ruby-2.5.1/bin/ruby_executable_hooks:24:in `<main>'
Tasks: TOP => db:migrate:status
(See full trace by running task with --trace)
What I've done so far
I have edited the pg_hba.conf file to show the following:
local all postgres md5
local all all md5
host all all 127.0.0.1/32 md5
host all all ::1/128 md5
local replication all peer
host replication all 127.0.0.1/32 md5
host replication all ::1/128 md5
and restarted the service. No luck. Same error. The first error I got prior to this was invalid password for postgresql, so i had to change one of the "peer" options to "md5"
If I look into my config/database.yml file, this is what it looks like:
# SQLite version 3.x
# gem install sqlite3
#
# Ensure the SQLite 3 gem is defined in your Gemfile
# gem 'sqlite3'
#
default: &default
adapter: postgresql
pool: 5
timeout: 5000
encoding: unicode
username: postgres
database: <%= Rails.application.credentials.dig(:database, Rails.env.to_sym, :database_name) %>
# username: <%= Rails.application.credentials.dig(:database, Rails.env.to_sym, :database_user_name) %>
# password: <%= Rails.application.credentials.dig(:database, Rails.env.to_sym, :database_password) %>
development:
<<: *default
test:
<<: *default
staging:
<<: *default
production:
<<: *default
and when I edit the credentials with rake (using EDITOR=vim rails credentials:edit), this is what this file looks like:
# aws:
# access_key_id: 123
# secret_access_key: 345
# Used as the base secret for all MessageVerifiers in Rails, including the one protecting cookies.
secret_key_base: <my long key redacted for stackoverflow>
database:
development:
database_name: development
database_user_name: postgres
database_password: <redacted for stackoverflow>
test:
database_name: test
database_user_name: postgres
database_password: <redacted for stackoverflow>
production:
database_name: production
database_user_name: postgres
database_password: <redacted for stackoverflow>
I feel like I've been going hours deep down the rabbit hole and cannot figure out how to get this Rails application working with Postgresql.
I have taken a look at this post here: PG::ConnectionBad fe_sendauth: no password supplied and have tried its suggestion with no luck, and even here How to resolve the error 'fe_sendauth: no password supplied' in Rails using PostgreSQL? with no luck either. I don't have host: '' or host: 'localhost' anywhere in the config/database.yml file (I've tried adding it and still didn't work), so I'm not quite sure this has anything to do with anything here for me.
Any other suggestions?
Add your username and password in production: in database.yml
So I have been looking everywhere to try and find a solution to this and i have had no luck up to now. I'm ruby on rails so i could very well be missing something basic or be looking in the wrong place for the solution, so i thought i'd just ask. I have a rails API which i forked from my organization and I want to run it locally. I got stuck running this line in the terminal
bundle exec rake create:db
and got this error, I don't really know what to do :/ If this question has already been answered just point me there and i'll go figure it out! Thank you.
Admins-MacBook-Pro:environments nathanshanko$ bundle exec rake db:create
(in /Users/nathanshanko/Desktop/git-repos/voke_api)
rake aborted!
KeyError: Cannot load `Rails.application.database_configuration`:
key not found: "DB_ENV_POSTGRESQL_USER"
(erb):7:in `fetch'
(erb):7:in `'
/Users/nathanshanko/.rvm/gems/ruby-2.3.0/gems/railties-4.2.6/lib/rails/application/configuration.rb:104:in `database_configuration'
/Users/nathanshanko/.rvm/gems/ruby-2.3.0/gems/activerecord-4.2.6/lib/active_record/railtie.rb:41:in `block (3 levels) in '
/Users/nathanshanko/.rvm/gems/ruby-2.3.0/bin/ruby_executable_hooks:15:in `eval'
/Users/nathanshanko/.rvm/gems/ruby-2.3.0/bin/ruby_executable_hooks:15:in `'
KeyError: key not found: "DB_ENV_POSTGRESQL_USER"
(erb):7:in `fetch'
(erb):7:in `'
/Users/nathanshanko/.rvm/gems/ruby-2.3.0/gems/railties-4.2.6/lib/rails/application/configuration.rb:104:in `database_configuration'
/Users/nathanshanko/.rvm/gems/ruby-2.3.0/gems/activerecord-4.2.6/lib/active_record/railtie.rb:41:in `block (3 levels) in '
/Users/nathanshanko/.rvm/gems/ruby-2.3.0/bin/ruby_executable_hooks:15:in `eval'
/Users/nathanshanko/.rvm/gems/ruby-2.3.0/bin/ruby_executable_hooks:15:in `'
Tasks: TOP => db:create => db:load_config
(See full trace by running task with --trace)
Here is my database.yml file
common: &common
adapter: postgresql
encoding: utf8
reconnect: true
pool: <%= ENV['DB_ENV_POSTGRESQL_POOL'] || 5 %>
database: <%= ENV['DB_ENV_POSTGRESQL_DB'] || 'voke_api' %>
username: <%= ENV.fetch('DB_ENV_POSTGRESQL_USER') %>
password: <%= ENV['DB_ENV_POSTGRESQL_PASS'] %>
host: <%= ENV.fetch('DB_PORT_5432_TCP_ADDR') %>
port: <%= ENV['DB_PORT_5432_TCP_PORT'] %>
development:
<<: *common
production:
<<: *common
staging:
<<: *common
test:
<<: *common
It sounds like you're missing some env vars that define your database credentials. You'll want to set these up (either via the command line, or something like a .env or application.yml file, depending on your project set up).
The error you're getting on DB_ENV_POSTGRESQL_USER is due to the ENV.fetch, which raises an IndexError if the key isn't found. You may also be missing other env vars, but ENV['xyz'] will fail silently without throwing any errors.
First, I do really apologize, since I'm still newbie on this.
I was trying to install Fat Free CRM by following the instruction on this following sites:
http://www.blogdugeek.fr/crm-installation-fat-free-crm-debian-squeeze/
http://guides.fatfreecrm.com/Setup-Linux-or-Mac-OS.html
As I follow the instructions, I've encounter some errors and resolved some. However, upon executing this command:
RAILS_ENV=production rake db:create db:migrate crm:settings:load
I was stuck in this command line and here are the following errors that I've been stuck with:
rake aborted!
NoMethodError: undefined method `each' for #<String:0x00000003a27a58>
/usr/local/rvm/gems/ruby-2.2.4/gems/activerecord-4.2.6/lib/active_record/connection_adapters/connection_specification.rb:150:in `resolve_all'
/usr/local/rvm/gems/ruby-2.2.4/gems/activerecord-4.2.6/lib/active_record/connection_handling.rb:69:in `resolve'
/usr/local/rvm/gems/ruby-2.2.4/gems/activerecord-4.2.6/lib/active_record/core.rb:46:in `configurations='
/usr/local/rvm/gems/ruby-2.2.4/gems/activerecord-4.2.6/lib/active_record/railties/databases.rake:5:in `block (2 levels) in <top (required)>'
/usr/local/rvm/gems/ruby-2.2.4/bin/ruby_executable_hooks:15:in `eval'
/usr/local/rvm/gems/ruby-2.2.4/bin/ruby_executable_hooks:15:in `<main>'
Tasks: TOP => db:create => db:load_config
(See full trace by running task with --trace)
As I've search for more related issue, I found some, but it's still no use.
Also, here are some data that might be needed:
Ruby Version
ruby 2.2.4p230 (2015-12-16 revision 53155) [x86_64-linux]
Rails Version
Rails 4.2.6
Here are the error lines
connection_specification.rb
def resolve(config)
if config
resolve_connection config
elsif env = ActiveRecord::ConnectionHandling::RAILS_ENV.call
resolve_symbol_connection env.to_sym
else
raise AdapterNotSpecified
end
end
# Expands each key in #configurations hash into fully resolved hash
def resolve_all
config = configurations.dup
config.each do |key, value| <---- Error line
config[key] = resolve(value) if value
end
config
end
connection_handling.rb
class MergeAndResolveDefaultUrlConfig # :nodoc:
def initialize(raw_configurations)
#raw_config = raw_configurations.dup
#env = DEFAULT_ENV.call.to_s
end
# Returns fully resolved connection hashes.
# Merges connection information from `ENV['DATABASE_URL']` if available.
def resolve
Error line ----> ConnectionAdapters::ConnectionSpecification::Resolver.new(config).resolve_all
end
private
def config
#raw_config.dup.tap do |cfg|
if url = ENV['DATABASE_URL']
cfg[#env] ||= {}
cfg[#env]["url"] ||= url
end
end
end
core.rb
def self.configurations=(config)
Error line ---> ##configurations = ActiveRecord::ConnectionHandling::MergeAndResolveDefaultUrlConfig.new(config).resolve
end
self.configurations = {}
# Returns fully resolved configurations hash
def self.configurations
##configurations
end
databases.rake
db_namespace = namespace :db do task :load_config do
Error line ----> ActiveRecord::Base.configurations = ActiveRecord::Tasks::DatabaseTasks.database_configuration || {}
ActiveRecord::Migrator.migrations_paths = ActiveRecord::Tasks::DatabaseTasks.migrations_paths
Here's the config/database.yml file.
# MySQL. Versions 4.1 and 5.0 are recommended.
#
# Install the MySQL driver:
# gem install mysql2
#
# And be sure to use new-style password hashing:
# http://dev.mysql.com/doc/refman/5.0/en/old-client.html
#------------------------------------------------------------------------------
development:&development
adapter:mysql2
encoding:utf8
database:fat_free_crm_development
pool:5
username:root
# password:
socket:/var/run/mysqld/mysqld.sock
# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
<<: *development
database: fat_free_crm_test
production:
adapter: mysql
encoding: utf8
database: fat_free_crm_production
pool: 5
username: root
password:
socket: /var/run/mysqld/mysqld.sock
socket: /tmp/mysql.sock
staging:
<<: *development
database: fat_free_crm_staging
Hope to hear and seek some advises and learning.
If there's need some more information, let me know.
Thanks,
Your database.yml is the problem. YAML requires a separator between the key and data.
So not like this:
production:
adapter:mysql
encoding:utf8
...
But like this:
production:
adapter: mysql
encoding: utf8
...
You need to correct all the lines in the file, because you have this error everywhere.
Check the database.yml file again. Don't add anything
ie the file format must be correct.
had unkowngly comment a line on to that was causing the error.