Rails 4/ActiveSupport: Circular dependency detected while autoloading constant User - ruby-on-rails-4

After running:
rails generate active_admin:resource Project
at the terminal I got the following error:
/Users/thalatta/.rbenv/versions/1.9.3-p448/lib/ruby/gems/1.9.1/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:460:in `load_missing_constant': Circular dependency detected while autoloading constant User (RuntimeError)
from /Users/thalatta/.rbenv/versions/1.9.3-p448/lib/ruby/gems/1.9.1/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:183:in `const_missing'
from /Users/thalatta/code/byrdtyme/app/admin/user.rb:1:in `<top (required)>'
Here is my Gemfile for reference:
source 'https://rubygems.org'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.0.0'
# Use sqlite3 as the database for Active Record
gem 'sqlite3'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 4.0.0'
gem 'launchy'
gem 'devise', github: 'plataformatec/devise'
gem 'responders', github: 'plataformatec/responders'
gem 'inherited_resources', github: 'josevalim/inherited_resources'
gem 'ransack'
gem 'activeadmin', github: 'gregbell/active_admin', branch: 'rails4'
gem 'formtastic', github: 'justinfrench/formtastic'
gem 'spork'
gem 'rspec-rails'
gem 'capybara', '1.1.2'
gem 'cancan'
#TODO figure out how to resolve this! don't werk with Rails 4
#gem 'audited-activerecord'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .js.coffee assets and views
gem 'coffee-rails'
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby
# Use jquery as the JavaScript library
gem 'jquery-rails'
gem 'rspec-rails'
gem 'factory_girl_rails', '~> 4.0'
gem 'faker'
gem 'haml'
# 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
I tried following this post's advice: Circular dependency detected while autoloading constant User, but unfortunately activesupport, as far as I know, does not have a github where I can post an issue or see if it has been resolved.
Thanks for your time!

Try removing the second mention of gem 'rspec-rails'
Also - check the first line of your Users Controller... it should read:
Class UsersController < ApplicationController
Someone has run in to this error before because they had 'UsersControllers' instead of UserController (see this post: Rails 4 Runtime error in controller: Circular dependency detected while autoloading constant).
Your new Gemfile will look like this:
source 'https://rubygems.org'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.0.0'
# Use sqlite3 as the database for Active Record
gem 'sqlite3'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 4.0.0'
gem 'launchy'
gem 'devise', github: 'plataformatec/devise'
gem 'responders', github: 'plataformatec/responders'
gem 'inherited_resources', github: 'josevalim/inherited_resources'
gem 'ransack'
gem 'activeadmin', github: 'gregbell/active_admin', branch: 'rails4'
gem 'formtastic', github: 'justinfrench/formtastic'
gem 'spork'
gem 'rspec-rails'
gem 'capybara', '1.1.2'
gem 'cancan'
#TODO figure out how to resolve this! don't werk with Rails 4
# gem 'audited-activerecord'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .js.coffee assets and views
gem 'coffee-rails'
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby
# Use jquery as the JavaScript library
gem 'jquery-rails'
gem 'factory_girl_rails', '~> 4.0'
gem 'faker'
gem 'haml'
# 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

Related

Leaflet markercluster rails not displaying marker

I am not get a graphic for my markercluster, just a number. I suspect the css is missing, but am not sure what I'm doing wrong. I get no errors in the console, and everythings works ok without markercluster.
Gemfile
source 'https://rubygems.org'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.2.5.1'
# Use postgresql as the database for Active Record
gem 'pg', '~> 0.15'
# 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'
end
group :development do
# Access an IRB console on exception pages or by using <%= console %> in views
gem 'web-console', '~> 2.0'
end
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
gem 'activerecord-postgis-adapter'
gem 'leaflet-rails'
gem 'leaflet-markercluster-rails'
gem 'gon'
application.js
//= require jquery
//= require jquery_ujs
//= require turbolinks
//= require leaflet
//= require leaflet-google
//= require leaflet.markercluster
//= require_tree
application.css
*= require leaflet
*= require leaflet.markercluster
*= require leaflet.markercluster.default
*= require_tree .
*= require_self
coffeescript
$ ->
map = L.map("mapid").setView([47.6345153, -122.3208297], 18)
map.options.maxZoom = 22
map.options.bounceAtZoomLimits = true
googleLayer = new L.Google("ROADMAP")
map.addLayer googleLayer
markers = L.markerClusterGroup()
for i in[0...10]
markers.addLayer L.marker([47.6345 + (Math.random() / 2000), -122.3208 + (Math.random() / 2000)])
markers.refreshClusters
map.addLayer markers
Any help would be wonderful.
As it turned out leaflet-markercluster-rails was using code from leaflet-markercluster 0.4, not the more current 0.7. From what I can tell, that's the root of my entire problem. :)

In Rails 4+ app, I have deployed App to heroku but static Images are not loading in production but working in development

I have Tried every answer for last two days but nothing worked for me. Problem is my static images doesn't get loaded in production but work fines in Development. I have even bundle exec rake assets:precompile RAILS_ENV=production. This works and precompile my assets. I see static images in Public/Assets folder.
Gemfile
source 'http://rubygems.org'
gem 'rails', '4.2.4'
group :development do
gem 'sqlite3'
end
group :production do
gem 'pg'
end
gem 'searchkick'
gem 'cocoon'
gem 'bootstrap-sass', '~> 3.3.6'
gem 'sass-rails', '~> 5.0'
gem 'uglifier', '>= 1.3.0'
gem 'coffee-rails', '~> 4.1.0'
gem 'coffee-script-source', '1.8.0'
gem 'jquery-rails'
gem 'turbolinks'
gem 'jbuilder', '~> 2.0'
gem 'sdoc', '~> 0.4.0', group: :doc
gem 'tinymce-rails', '~> 4.3', '>= 4.3.8'
gem 'haml'
gem 'simple_form'
gem 'paperclip', '~> 4.3.6'
gem 'omniauth-facebook'
gem "omniauth-google-oauth2", "~> 0.2.1"
gem 'acts_as_votable'
gem 'aws-sdk', '~> 1.66.0'
gem 'foreman'
gem 'puma'
gem 'omniauth'
gem 'jquery-turbolinks', '~> 2.1'
gem 'rack-mini-profiler', '~> 0.10.1'
gem 'execjs', '~> 2.7'
group :development, :test do
gem 'byebug'
end
group :development do
gem 'web-console', '~> 2.0'
end
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
production.rb
Rails.application.configure do
# Settings specified here will take precedence over those in config/application.rb.
# Code is not reloaded between requests.
config.cache_classes = true
# Eager load code on boot. This eager loads most of Rails and
# your application in memory, allowing both threaded web servers
# and those relying on copy on write to perform better.
# Rake tasks automatically ignore this option for performance.
config.eager_load = true
# Full error reports are disabled and caching is turned on.
config.consider_all_requests_local = true
config.action_controller.perform_caching = true
# Enable Rack::Cache to put a simple HTTP cache in front of your application
# Add `rack-cache` to your Gemfile before enabling this.
# For large-scale production use, consider using a caching reverse proxy like
# NGINX, varnish or squid.
# config.action_dispatch.rack_cache = true
# Disable serving static files from the `/public` folder by default since
# Apache or NGINX already handles this.
config.serve_static_files = ENV['RAILS_SERVE_STATIC_FILES'].present?
# Compress JavaScripts and CSS.
config.assets.js_compressor = :uglifier
# config.assets.css_compressor = :sass
# Do not fallback to assets pipeline if a precompiled asset is missed.
config.assets.compile = false
# Asset digests allow you to set far-future HTTP expiration dates on all assets,
# yet still be able to expire them through the digest params.
config.assets.digest = true
# `config.assets.precompile` and `config.assets.version` have moved to config/initializers/assets.rb
# Specifies the header that your server uses for sending files.
# config.action_dispatch.x_sendfile_header = 'X-Sendfile' # for Apache
# config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for NGINX
# Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
# config.force_ssl = true
# Use the lowest log level to ensure availability of diagnostic information
# when problems arise.
config.log_level = :debug
# Prepend all log lines with the following tags.
# config.log_tags = [ :subdomain, :uuid ]
# Use a different logger for distributed setups.
# config.logger = ActiveSupport::TaggedLogging.new(SyslogLogger.new)
# Use a different cache store in production.
# config.cache_store = :mem_cache_store
# Enable serving of images, stylesheets, and JavaScripts from an asset server.
# config.action_controller.asset_host = 'http://assets.example.com'
# Ignore bad email addresses and do not raise email delivery errors.
# Set this to true and configure the email server for immediate delivery to raise delivery errors.
# config.action_mailer.raise_delivery_errors = false
# Enable locale fallbacks for I18n (makes lookups for any locale fall back to
# the I18n.default_locale when a translation cannot be found).
config.i18n.fallbacks = true
# Send deprecation notices to registered listeners.
config.active_support.deprecation = :notify
# Use default logging formatter so that PID and timestamp are not suppressed.
config.log_formatter = ::Logger::Formatter.new
# Do not dump schema after migrations.
config.active_record.dump_schema_after_migration = false
config.assets.precompile += %w(*.png *.jpg *.jpeg *.gif)
end
One more interesting thing i found was even though my static images are in public/assets,image tag have src link like images/abc.jpg, Not pointing to public assets images
Code
<%= link_to root_path,class:"navbar-brand" do %>
<h1><%= image_tag("logo",alt:"Bitnotes") %></h1>
<% end %>
You can try by adding this gem 'rails_12factor', group: :production to your Gemfile and deploy to Heroku again. And you don't need to set config.serve_static_files in your production.rb file.
After Trying 4 Days, Here is Solution to above Problem
gem 'tinymce-rails', '~> 4.3', '>= 4.3.8'
gem doesn't let assets to precompile. So I removed the above gem and removed
//= require tinymce
//= require tinymce-jquery
from the application.js
Then made this config.assets.compile = true change in production.rb.
Finally Precompiled assets with
bundle exec rake assets:precompile RAILS_ENV=production
committed all the changes and pushed to heroku with
git push heroku master

Cucumber fails with error undefined method `visit'

running
rake cucumber
passes even untested features.
while running
cucumber features/something.feature
throws
undefined method `visit' for #<Object:0x00000001b13950> (NoMethodError)
I have googled some github issues where they talk about it but to no relief.
This Running Capybara without rack produces errors when using url parameters was helpful but didn't resovle my issue
UPDATE
I did touch on the following from capybara readme
Using Capybara with Cucumber
The cucumber-rails gem comes with Capybara support built-in. If you
are not using Rails, manually load the capybara/cucumber module:
require 'capybara/cucumber'
Capybara.app = MyRackApp
But in which file to include the above?
I tried adding the above to env.rb and got this error:
uninitialized constant ActionController (NameError)
Now after commenting it, I still get the same error.
Here is the gemfile:
source 'https://rubygems.org'
#add dependency
gem 'diff-lcs', ">= 1.2.0"
gem 'rspec-expectations', "~> 3.0.0"
#add cucumber
group :test do
gem 'cucumber-rails', :require => false
# database_cleaner is not required, but highly recommended
#gem 'database_cleaner', "~> 1.2.0"
gem 'database_cleaner'
end
#add rspec
group :development, :test do
gem 'rspec-rails', '~> 3.0'
gem "capybara"
gem 'factory_girl_rails'
gem 'watir-webdriver'
gem 'selenium-webdriver', '2.35.0'
gem 'rubyzip'
gem 'zip-zip'
end
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.1.7'
# Use sqlite3 as the database for Active Record
gem 'sqlite3'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 4.0.3'
# 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
# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
gem 'spring', group: :development
Here is spec/spec_helper.rb (truncated)
ENV["RAILS_ENV"] ||= 'test'
require File.expand_path("../../config/environment", __FILE__)
require 'capybara'
include Capybara::DSL # Adding this line solved the error
require 'rspec/rails'
Dir[Rails.root.join("spec/support/**/*.rb")].each { |f| require f }
ActiveRecord::Migration.maintain_test_schema!
RSpec.configure do |config|
# Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
config.fixture_path = "#{::Rails.root}/spec/fixtures"
config.use_transactional_fixtures = true
config.infer_base_class_for_anonymous_controllers = false
config.order = "random"
config.infer_spec_type_from_file_location!
config.include Capybara::DSL
end
Here is env.rb
require 'capybara'
require 'capybara/dsl'
require 'capybara/cucumber'
#require 'capybara/rails'
#require 'capybara/session'
ActionController::Base.allow_rescue = false
begin
DatabaseCleaner.strategy = :transaction
rescue NameError
raise "You need to add database_cleaner to your Gemfile (in the :test group) if you wish to use it."
end
Cucumber::Rails::Database.javascript_strategy = :truncation
May this answer help some lost soul.
Finally got the answer here: Cucumber headless xvfb ubuntu
For anyone wanting to do headless browsing, this rescued me:
Included following in env.rb:
require 'capybara'
require 'capybara/cucumber'
require 'cucumber/rails'
require 'capybara/rails'
require 'capybara/dsl'
require 'selenium/webdriver'
$port = <port_number>
#Capybara.app_host = '<localhost>:<port>'
Capybara.configure do |config|
config.run_server = true
#Capybara.default_host = "<localhost>:<port>"
config.default_driver = :selenium
#config.app = "make sure this isn't nil"
config.app_host = "<hostname>:#{$port.to_s}"
config.server_port = $port
end
#To add chrome webdriver do the following in your machine
#chmod +x chromedriver
#sudo mv chromedriver /usr/local/share/
#sudo ln -s /usr/local/share/chromedriver /usr/local/bin/chromedriver
#sudo ln -s /usr/local/share/chromedriver /usr/bin/chromedriver
#Register chrome as default Capybara webdriver
Capybara.register_driver :firefox do |app|
# optional
client = Selenium::WebDriver::Remote::Http::Default.new
# optional
#client.timeout = 120
Capybara::Selenium::Driver.new(app, :browser => :firefox, :http_client => client)
end
#set default js driver
Capybara.javascript_driver = :firefox
#Include headless
require_relative 'headless'
headless is a relative rb file headless.rb:
if Capybara.current_driver == :selenium || Capybara.default_driver == :selenium
require 'headless'
headless = Headless.new
headless.start
at_exit do
headless.destroy
end
end
Both env.rb and headless.rb are in features/support folder
I am able to to do bdd and web testing.

Can't resolve Gemfile.lock merge error

I tried to run bundle install and this happens, and I can't see to fix it. I don't think there are any merge conflicts in my gem file that I haven't fixed.. but I still can't get rid of this error. How can I do so?
Your Gemfile.lock contains merge conflicts.
Run git checkout HEAD -- Gemfile.lock first to get a clean lock.
this is my gem file:
source 'https://rubygems.org'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.0.8'
group :test, :development do
gem 'rspec-rails'
end
group :test do
gem 'capybara'
#gem 'selenium-webdriver'
end
# Use sqlite3 as the database for Active Record
group(:development, :test) do
gem 'sqlite3'
end
group :production do
gem 'pg'
gem 'rails_12factor'
end
# Use SCSS for stylesheets
gem 'sass-rails', '~> 4.0.2'
# add bootstrap gem
gem 'bootstrap-sass'
# 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', '~> 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', '~> 3.1.7'
# Use unicorn as the app server
# gem 'unicorn'
# Use Capistrano for deployment
# gem 'capistrano', group: :development
# Use debugger
# gem 'debugger', group: [:development, :test]
gem 'rubyzip', '0.9.9'
It's actually very straightforward. Here is an article that explains the difference between the gemfile and the gemfile.lock. (You can edit Gemfile.lock to get rid of the conflicts manually)
http://rubyinrails.com/2013/12/what-is-gemfile-lock/

Bootstrap Rails 4 sass layout not working

I'm using followings:
Rails 4.1.0
ruby 2.1.1p76 (2014-02-24 revision 45161) [x86_64-linux]
rvm 1.25.25 (stable) by Wayne E. Seguin ,
Michal Papis [https://rvm.io/]
My Gemfile:
source 'https://rubygems.org'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.1.0'
# Use sqlite3 as the database for Active Record
gem 'sqlite3'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 4.0.3'
gem 'bootstrap-sass-extras'
# 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
# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
gem 'spring', group: :development
# 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
# Use debugger
# gem 'debugger', group: [:development, :test]
and i have done the following tasks to achieve bootstrap-sass-fluid layout through my railsapp :
bundle install
rails g bootstrap:install
rails g bootstrap:layout application fluid
rails g scaffold Post title:string description:text
rake db:migrate
rails g bootstrap:themed Posts
and i have these files in my assests folder under my rails app :
/home/pallavsharma/Workspace/testapp/app/assets/stylesheets/application.css
/home/pallavsharma/Workspace/testapp/app/assets/stylesheets/posts.css.scss
/home/pallavsharma/Workspace/testapp/app/assets/stylesheets/scaffolds.css.scss
but still i dont have my bootstrap layout in my app
My application.css file contents:
/*
This is a manifest file that'll be compiled into application.css,
which will include all the files
listed below.
*
Any CSS and SCSS file within this directory,
lib/assets/stylesheets, vendor/assets/stylesheets,
or vendor/assets/stylesheets of plugins, if any, can be referenced
here using a relative path.
*
Blockquote
* You're free to add application-wide styles to this file and they'll
appear at the bottom of the
compiled file so the styles you add here take precedence over
styles defined in any styles
defined in the other CSS/SCSS files in this directory. It is
generally better to create a new
file per style scope.
*
*= require_tree .
*= require_self
*/
What else needs to be mentioned please tell.
application.css.scss should be:
/*
*= require bootstrap
*= require_tree .
*= require_self
*/
Also need to mention this gem in gemfile
gem 'bootstrap-sass', '~> 3.1.1'
then
bundle install
and it works.