dotenv varibles are not loading in new Rails 4 app - ruby-on-rails

Ruby version 2.1.6p336
Rails version 4.2.1
Gemfile:
source 'https://rubygems.org'
gem 'dotenv-rails', :groups => [:development, :test]
gem 'zendesk_api', '~> 1.13.0'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.2.1'
# Use sqlite3 as the database for Active Record
gem 'sqlite3'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 5.0'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .coffee assets and views
gem 'coffee-rails', '~> 4.1.0'
# See https://github.com/rails/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby
# Use jquery as the JavaScript library
gem 'jquery-rails'
# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
gem 'turbolinks'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.0'
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', '~> 0.4.0', group: :doc
# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'
# Use Unicorn as the app server
# gem 'unicorn'
# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development
group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug'
# Access an IRB console on exception pages or by using <%= console %> in views
gem 'web-console', '~> 2.0'
# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
gem 'spring'
end
config/.env:
ZD_EMAIL= "hermes#olympus.com"
ZD_API_TOKEN= "ἙρμῆςκριοφόροςἈργειφόντης"
ZD_DOMAIN= "olympus.zendesk.com"
config/application.rb:
require File.expand_path('../boot', __FILE__)
require 'rails/all'
# Require the gems listed in Gemfile, including any gems
# you've limited to :test, :development, or :production.
Bundler.require(*Rails.groups)
module ZendeskSupportPortal
class Application < Rails::Application
# Settings in config/environments/* take precedence over those specified here.
# Application configuration should go into files in config/initializers
# -- all .rb files in that directory are automatically loaded.
# Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
# Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
# config.time_zone = 'Central Time (US & Canada)'
# The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
# config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
# config.i18n.default_locale = :de
# Do not swallow errors in after_commit/after_rollback callbacks.
config.active_record.raise_in_transactional_callbacks = true
end
end
I'm not trying to load them for a production environment, I'm trying to load them the standard way, just for development. But when I start the rails console and check, for example, ENV['ZD_EMAIL'], it returns nil.
I've tried everything mentioned in these two issues (in dotenv repo):
https://github.com/bkeepers/dotenv/issues/144
https://github.com/bkeepers/dotenv/issues/191
This is my first time using dotenv. Although the installation instructions are simple, I must be making a rookie mistake. Please enlighten me. Thanks!

It was a rookie mistake. I should have put the .env file in the root directory instead of config/.env. Putting it in the root directory (per the installation instructions) solved the issue.

Related

Ruby on Rails will not register active_admin upon server startup (http://localhost:3001/admin)

I am currently creating my first React-on-Rails project. I have an issue with loading the server when trying to run the RoR api.
Application.rb
require_relative 'boot'
require "rails"
# Pick the frameworks you want:
require "active_model/railtie"
require "active_job/railtie"
require "active_record/railtie"
require "active_storage/engine"
require "action_controller/railtie"
require "action_mailer/railtie"
require "action_view/railtie"
require "action_cable/engine"
require "sprockets/railtie"
require "rails/test_unit/railtie"
# Require the gems listed in Gemfile, including any gems
# you've limited to :test, :development, or :production.
Bundler.require(*Rails.groups)
module ListOfIngredients
class Application < Rails::Application
# Initialize configuration defaults for originally generated
Rails version.
config.load_defaults 5.2
# Settings in config/environments/* take precedence over those
specified here.
# Application configuration can go into files in
config/initializers
# -- all .rb files in that directory are automatically loaded
after loading
# the framework and any gems in your application.
# Only loads a smaller set of middleware suitable for API only
apps.
# Middleware like session, flash, cookies can be added back
manually.
# Skip views, helpers and assets when generating a new resource.
config.api_only = true
# Middleware for ActiveAdmin
config.middleware.use Rack::MethodOverride
config.middleware.use ActionDispatch::Flash
config.middleware.use ActionDispatch::Cookies
config.middleware.use ActionDispatch::Session::CookieStore
end
end
Gemfile.
source 'https://rubygems.org'
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
ruby '2.5.1'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '~> 5.2.0'
# Use Puma as the app server
gem 'puma', '~> 3.11'
# Build JSON APIs with ease. Read more:
https://github.com/rails/jbuilder
# gem 'jbuilder', '~> 2.5'
# Use Redis adapter to run Action Cable in production
# gem 'redis', '~> 4.0'
# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'
# Use ActiveStorage variant
# gem 'mini_magick', '~> 4.8'
# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development
# Reduces boot times through caching; required in config/boot.rb
gem 'bootsnap', '>= 1.1.0', require: false
# Use Rack CORS for handling Cross-Origin Resource Sharing
(CORS), making cross-origin AJAX possible
# gem 'rack-cors'
group :development, :test do
# Use sqlite3 as the database for Active Record
gem 'sqlite3'
# Call 'byebug' anywhere in the code to stop execution and get a
debugger console
gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
end
group :development do
gem 'listen', '>= 3.0.5', '< 3.2'
# Spring speeds up development by keeping your application
running in the background. Read more:
https://github.com/rails/spring
gem 'spring'
gem 'spring-watcher-listen', '~> 2.0.0'
end
group :production do
# Use postgres as the database for production
gem 'pg'
end
# ActiveAdmin
gem 'devise'
gem 'activeadmin'
# Windows does not include zoneinfo files, so bundle the tzinfo-
data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw,
:jruby]
I have also set up two controllers as follows.
api_controller.rb
class ApiController < ActionController::API
end
application_controller.rb
class ApplicationController < ActionController::Base
protect_from_forgery with: :exception
end
When I am running rails on localhost 3001, I somehow still end up with the error message.
Sprockets::Rails::Helper::AssetNotFound in ActiveAdmin::Devise::Sessions#new
where are active admins assets supposed to go when rails 5 api doesn't contain an assets folder?
I'm pretty sure ActiveAdmin requires sprockets. Did you run?
rails generate devise:install
You might also need to run
rails generate devise:views
For more info on vies see the devise wiki
And perhaps a look at this answer and this one too
UPDATE:
If you are following instructions at this tutorial you might wanna try to comment out this line in application.rb
# require "sprockets/railtie"

uninitialized constant ActiveSupport::EventedFileUpdateChecker in env config file

I'm new with Ruby on Rails. After run the 'bundle' command for update/install, When i try to do rails s or rails g mongoid:config console returns this message that start with:
/home/myUser/proyect/config/environments/development.rb:50:in `block in <top (required)>': uninitialized constant ActiveSupport::EventedFileUpdateChecker (NameError)
This is my Gemfile (Yes, i want to use MongoDB as the Database):
source 'https://rubygems.org'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.2.6'
# Use sqlite3 as the database for Active Record
gem 'sqlite3'
# Use Mongoid as the database
gem 'mongoid', '~> 5.1.0'
# Use bson
gem 'bson_ext'
# Use Puma as the app server
gem 'puma', '~> 3.0'
#Use Haml for html
gem 'haml'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 5.0'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .coffee assets and views
gem 'coffee-rails', '~> 4.1.0'
# See https://github.com/rails/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby
# Use jquery as the JavaScript library
gem 'jquery-rails'
# Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks
gem 'turbolinks', '~> 5.x'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.0'
# Use Redis adapter to run Action Cable in production
# gem 'redis', '~> 3.0'
# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'
# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development
group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug', platform: :mri
end
group :development do
# Access an IRB console on exception pages or by using <%= console %> anywhere in the code.
gem 'web-console'
gem 'listen', '~> 3.0.5'
# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
gem 'spring'
gem 'spring-watcher-listen', '~> 2.0.0'
end
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
And the config/environments/development.rb file:
Rails.application.configure do
# Settings specified here will take precedence over those in config/application.rb.
# In the development environment your application's code is reloaded on
# every request. This slows down response time but is perfect for development
# since you don't have to restart the web server when you make code changes.
config.cache_classes = false
# Do not eager load code on boot.
config.eager_load = false
# Show full error reports.
config.consider_all_requests_local = true
# Enable/disable caching. By default caching is disabled.
if Rails.root.join('tmp/caching-dev.txt').exist?
config.action_controller.perform_caching = true
config.cache_store = :memory_store
config.public_file_server.headers = {
'Cache-Control' => 'public, max-age=172800'
}
else
config.action_controller.perform_caching = false
config.cache_store = :null_store
end
# Don't care if the mailer can't send.
config.action_mailer.raise_delivery_errors = false
config.action_mailer.perform_caching = false
# Print deprecation notices to the Rails logger.
config.active_support.deprecation = :log
# Raise an error on page load if there are pending migrations.
config.active_record.migration_error = :page_load
# Debug mode disables concatenation and preprocessing of assets.
# This option may cause significant delays in view rendering with a large
# number of complex assets.
config.assets.debug = true
# Raises error for missing translations
# config.action_view.raise_on_missing_translations = true
# Use an evented file watcher to asynchronously detect changes in source code,
# routes, locales, etc. This feature depends on the listen gem.
config.file_watcher = ActiveSupport::EventedFileUpdateChecker
end
According to Rails changelogs, config.file_watcher option has been introduced in Rails 5. It allows you to have an auto-reloading based on your file changes. This feature depends on the listener gem, and you have it listed in your gemfile. But what seems suspicious to me is your Rails version!
gem 'rails', '4.2.6'
# but rails 4 does not support that feature!
Looks like you've got a Gemfile (or development.rb config?) copied from another version of Rails framework, another project, or manually changed your gemfile version to unappropriate state.
Two options I could suggest you are:
To change your rails gemfile version to the cutting edge one as follows:
gem 'rails', github: 'rails/rails'
And bundle once more;
To remove config.file_watcher line from your config file.
tl;dr: Re-create your Rails project, providing the specific Rails version.
Often this occurs because you have a newer version of Rails installed than the one called for in your .railsrc or template.rb.
If this is the case, when you run rails new my_new_app, the newest version is used by default for the earlier steps of the process, but then once the template/railsrc version is installed, latter steps use this version. This causes compatibility issues.
You can verify that this is your problem by comparing the output of rails -v (in the directory where you called rails new) with what's in your .railsrc or template.rb. If they are different, there is an easy fix:
Recreate your Rails app, specifying the same Rails version from your .railsrc or template.rb in the command line call:
rails _4.2.5.1_ new my_new_app
if you remove config.file_watcher = ActiveSupport::EventedFileUpdateChecker it will work. It detects changes in the source code to refresh asynchronously, but it also depends on the listen gem and as you're a beginner, it will only cause trouble to you. Should work without it.

Cannot use db migrate when deploy to Heroku

I tried to deploy my code to heroku. It only work with
config.assets.initialize_on_precompile = false
in my application.rb despite I'm using Rails 4.2.3. But when I tried to use
heroku run rake db:migrate
It cannot work correctly with error:
Name Error: Undefined local variable or method config for main:Object
/app/config/application.rb:7 in `'
Here is my Gemfile
source 'https://rubygems.org'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.2.3'
group :production do
#Use PG
gem 'pg'
end
group :development do
# Use sqlite3 as the database for Active Record
gem 'sqlite3'
end
# Use SCSS for stylesheets
gem 'sass-rails', '~> 5.0.1'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .js.coffee assets and views
gem 'coffee-rails', '~> 4.0.0'
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby
# Use jquery as the JavaScript library
gem 'jquery-rails'
# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
gem 'turbolinks'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.0'
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', '~> 0.4.0', group: :doc
# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'
# Use unicorn as the app server
# gem 'unicorn'
#Use Heroku
gem 'rails_12factor', group: 'production'
#Use bootstrap
gem 'bootstrap', '~> 4.0.0.alpha3'
gem 'autoprefixer-rails'
#Use Redcarpet
gem 'redcarpet'
#Use SQLite
#gem 'sqlite3', '1.3.11'
# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development
# Use debugger
# gem 'debugger', group: [:development, :test]
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin]
And here is application.rb
require File.expand_path('../boot', __FILE__)
require 'rails/all'
# Require the gems listed in Gemfile, including any gems
# you've limited to :test, :development, or :production.
# Prevent initializing the application before assets are precompiled (required for heroku)
config.assets.initialize_on_precompile = false
Bundler.require(*Rails.groups)
module Blog
class Application < Rails::Application
# Settings in config/environments/* take precedence over those specified here.
# Application configuration should go into files in config/initializers
# -- all .rb files in that directory are automatically loaded.
# Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
# Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
# config.time_zone = 'Central Time (US & Canada)'
# The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
# config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
# config.i18n.default_locale = :de
end
end
Any solutions for my stuck point?
The log when I tried : git push heroku master with
config.assets.initialize_on_precompile = false
put in production.rb
http://i.stack.imgur.com/9rXp9.png
Sorry I cannot put img since I'm newbie.
Remove config.assets.initialize_on_precompile = false from application.rb
If you need to have this line in your rails application it should go in: app/config/environments/production.rb

Deploy masonry in Heroku

Good day,
I made an app with masonry and js.coffee to make something like "pins" in my app, but when I deploy to Heroku don't work like suppose to do.
This is my gem file
source 'https://rubygems.org'
ruby '2.1.4'
gem 'binding_of_caller'
gem 'masonry-rails', '~> 0.2.0'
gem 'haml'
gem 'high_voltage', '~> 2.3.0'
gem 'activevalidators'
gem 'paperclip', github: 'thoughtbot/paperclip'
gem 'simple_form', '~>3.0.2'
gem 'acts_as_votable'
gem 'bootstrap-sass'
gem 'devise', '~> 3.4.0'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.2.1'
# Use sqlite3 as the database for Active Record
# Use SCSS for stylesheets
gem 'sass-rails', '~> 5.0'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .coffee assets and views
gem 'coffee-rails', '~> 4.1.0'
# See https://github.com/rails/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby
# Use jquery as the JavaScript library
gem 'jquery-rails'
# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
gem 'turbolinks'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.0'
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', '~> 0.4.0', group: :doc
# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'
# Use Unicorn as the app server
# gem 'unicorn'
# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development
group :assets do
gem 'therubyracer'
gem 'less-rails'
gem 'twitter-bootstrap-rails'
gem 'libv8'
end
group :production do
gem 'pg'
gem 'rails_12factor'
end
group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug'
gem 'sqlite3'
# Access an IRB console on exception pages or by using <%= console %> in views
gem 'web-console', '~> 2.0'
# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
gem 'spring'
end
My application.js
// This is a manifest file that'll be compiled into application.js, which will include all the files
// listed below.
//
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
// or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
//
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
// compiled file.
//
// Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
// about supported directives.
//
//= require jquery
//= require jquery_ujs
//= require bootstrap
//= require bootstrap-sprockets
//= require masonry/jquery.masonry
//= require turbolinks
//= require_tree .
My js.coffee to show pins
# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://coffeescript.org/
$ ->
$('#pins').imagesLoaded ->
$('#pins').masonry
itemSelector: '.box'
isFitWidth: true
My index for pins
- content_for :board do
= javascript_include_tag 'application', 'data-turbolinks-track' => true
#pins.transitions-enabled
- #pins.each do |pin|
.box.panel.panel-default
= link_to (image_tag pin.image.url), pin
%h2
= link_to pin.title, pin
%p.user
Ofertado por
= pin.user.name
%p.price
$
= pin.price
Am I doing something wrong?
If it works well under development and won't work upon deployment in heroku, you might have mistakenly configured your database.yml under config.
production:
adapter: postgresql
encoding: utf8
database: (copy database name from your heroku database info)
username: (copy username from your heroku database info)
password: TV9ncj-HR1FqNFihKm6zlsHhxU
host: (copy host from your heroku database info)
sslmode: require
and don't forget to do the rake db:migrate
if this is not the answer you were looking for, this might still be a little useful for you, if not now, maybe in the near future as you go along with your code.

Installing Doorkeeper : Uninitialized Constant Error

I'm attempting to install Doorkeeper on a fresh rails (4.0.2) install. After I add the gem to the gemfile and install it, I try to run
rails generate doorkeeper:install
and get the following error:
/Users/mam8cc/Projects/doorkeeper/config/application.rb:10:in `<module:Doorkeeper>': uninitialized constant Doorkeeper::Rails::Application (NameError)
from /Users/mam8cc/Projects/doorkeeper/config/application.rb:9:in `<top (required)>'
from /Users/mam8cc/.rvm/gems/ruby-2.0.0-p247/gems/railties-4.0.2/lib/rails/commands.rb:43:in `require'
from /Users/mam8cc/.rvm/gems/ruby-2.0.0-p247/gems/railties-4.0.2/lib/rails/commands.rb:43:in `<top (required)>'
from bin/rails:4:in `require'
from bin/rails:4:in `<main>'
My applications.rb
require File.expand_path('../boot', __FILE__)
require 'rails/all'
# Require the gems listed in Gemfile, including any gems
# you've limited to :test, :development, or :production.
Bundler.require(:default, Rails.env)
module Doorkeeper
class Application < Rails::Application
# Settings in config/environments/* take precedence over those specified here.
# Application configuration should go into files in config/initializers
# -- all .rb files in that directory are automatically loaded.
# Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
# Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
# config.time_zone = 'Central Time (US & Canada)'
# The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
# config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
# config.i18n.default_locale = :de
end
end
And my Gemfile for posterity
source 'https://rubygems.org'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.0.2'
# Use sqlite3 as the database for Active Record
gem 'sqlite3'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 4.0.0'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .js.coffee assets and views
gem 'coffee-rails', '~> 4.0.0'
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby
gem 'doorkeeper'
# Use jquery as the JavaScript library
gem 'jquery-rails'
# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
gem 'turbolinks'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 1.2'
group :doc do
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', require: false
end
# Use ActiveModel has_secure_password
# gem 'bcrypt-ruby', '~> 3.1.2'
# Use unicorn as the app server
# gem 'unicorn'
# Use Capistrano for deployment
# gem 'capistrano', group: :development
# Use debugger
# gem 'debugger', group: [:development, :test]
The issue is with your project having the same name as the package you are trying to install. Change the name of the project and it should work.

Resources