I have some problem after deploying my application Rails 4 with Heroku.
The application works very well in development, but it doesn't work totally in production. Some pages don't appear (Show) = white page, in particular for the pages which have a database. I think i have some problem with Sqlite3 and/or postgresql but i don't have to resolve the problem. Please help me.
GEMFILE
source 'https://rubygems.org'
ruby '2.2.3'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.1.8'
#modifie
group :development do
gem 'sqlite3'
end
group :production do
gem 'pg'
end
# Use SCSS for stylesheets
#gem 'sass-rails', '~> 4.0.3'
gem 'sass-rails', '~> 5.0', '>= 5.0.4'
# 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.3', '>= 2.3.2'
#modifie
group :doc do
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', '~> 0.4.0', 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-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]
# gem ajoutés
gem 'rails-i18n', '~> 4.0', '>= 4.0.6'
gem 'simple_form', '~> 3.2'
gem 'country-select', '~> 1.1', '>= 1.1.1'
gem 'bootstrap-sass', '~> 3.3', '>= 3.3.5.1'
gem 'cucumber-rails', :require => false
gem 'cucumber', '~> 2.1'
#gem 'bcrypt-ruby', '~> 3.1', '>= 3.1.5'
gem 'bcrypt', '~> 3.1', '>= 3.1.10'
gem 'devise', '~> 3.5', '>= 3.5.2'
gem 'paperclip'
gem 'builder'
# group :production do
# #use PostgreSQL as the database for Active Record
# gem 'pg', '~> 0.18.4'
# end
group :production do
gem 'rails_12factor' # Heroku
end
group :test, :development do
# RSpec
gem 'rspec-rails', ">= 2.0.0.beta"
gem 'rspec', '~> 3.3'
gem 'factory_girl_rails', '~> 4.5'
gem 'capybara', '~> 2.5'
gem 'email_spec', '~> 1.6'
end
CONFIG/ENVIRONMENTS/DEVELOPMENT.RB
Rails.application.configure do
# Settings specified here will take precedence over those in config/application.rb.
#For paperclip
Paperclip.options[:command_path] = "/usr/bin/"
# 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 and disable caching.
config.consider_all_requests_local = true
config.action_controller.perform_caching = false
# Don't care if the mailer can't send.
config.action_mailer.raise_delivery_errors = 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
# Adds additional error checking when serving assets at runtime.
# Checks for improperly declared sprockets dependencies.
# Raises helpful error messages.
config.assets.raise_runtime_errors = true
# Raises error for missing translations
# config.action_view.raise_on_missing_translations = true
#For devise
config.action_mailer.default_url_options = { :host => 'localhost:3000' }
# Mailer GMail
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
address: 'smtp.gmail.com',
port: 587,
user_name: 'XXXXXXX#gmail.com',
password: 'XXXXXX',
authentication: 'plain',
enable_starttls_auto: true }
end
CONFIG/ENVIRONMENTS/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 = false
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 Rails's static asset server (Apache or nginx will already do this).
config.serve_static_assets = false
# 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
# Generate digests for assets URLs.
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
# Set to :debug to see everything in the log.
config.log_level = :info
# 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
# Disable automatic flushing of the log to improve performance.
# config.autoflush_log = false
# 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
#For devise
config.action_mailer.default_url_options = { :host => "http://library-online-duofer.herokuapp.com/" }
# Mailer GMail
config.action_mailer.raise_delivery_errors = false
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
address: 'smtp.gmail.com',
port: 587,
user_name: 'XXXXX#gmail.com',
password: 'XXXXX',
authentication: 'plain',
enable_starttls_auto: true }
end
CONFIG/ENVIRONMENTS/TEST.RB
Rails.application.configure do
# Settings specified here will take precedence over those in config/application.rb.
# The test environment is used exclusively to run your application's
# test suite. You never need to work with it otherwise. Remember that
# your test database is "scratch space" for the test suite and is wiped
# and recreated between test runs. Don't rely on the data there!
config.cache_classes = true
# Do not eager load code on boot. This avoids loading your whole application
# just for the purpose of running a single test. If you are using a tool that
# preloads Rails for running tests, you may have to set it to true.
config.eager_load = false
# Configure static asset server for tests with Cache-Control for performance.
config.serve_static_assets = true
config.static_cache_control = 'public, max-age=3600'
# Show full error reports and disable caching.
config.consider_all_requests_local = true
config.action_controller.perform_caching = false
# Raise exceptions instead of rendering exception templates.
config.action_dispatch.show_exceptions = false
# Disable request forgery protection in test environment.
config.action_controller.allow_forgery_protection = false
# Tell Action Mailer not to deliver emails to the real world.
# The :test delivery method accumulates sent emails in the
# ActionMailer::Base.deliveries array.
config.action_mailer.delivery_method = :test
# Print deprecation notices to the stderr.
config.active_support.deprecation = :stderr
# Raises error for missing translations
# config.action_view.raise_on_missing_translations = true
end
It appears that when i type : git push heroku master
root#duong-SVE1513B1EW:~/Documents/Ruby_On_Rails# git push heroku master
Counting objects: 14, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (7/7), done.
Writing objects: 100% (8/8), 2.16 KiB | 0 bytes/s, done.
Total 8 (delta 5), reused 0 (delta 0)
remote: Compressing source files... done.
remote: Building source:
remote:
remote: -----> Using set buildpack heroku/ruby
remote: -----> Ruby app detected
remote: -----> Compiling Ruby/Rails
remote: -----> Using Ruby version: ruby-2.2.3
remote: ###### WARNING:
remote: Removing `Gemfile.lock` because it was generated on Windows.
remote: Bundler will do a full resolve so native gems are handled properly.
remote: This may result in unexpected gem versions being used in your app.
remote: In rare occasions Bundler may not be able to resolve your dependencies at all.
remote: https://devcenter.heroku.com/articles/bundler-windows-gemfile
remote:
remote: -----> Installing dependencies using bundler 1.9.7
remote: Running: bundle install --without development:test --path vendor/bundle --binstubs vendor/bundle/bin -j4
remote: Fetching gem metadata from https://rubygems.org/...........
remote: Fetching version metadata from https://rubygems.org/...
remote: Fetching dependency metadata from https://rubygems.org/..
remote: Resolving dependencies.....
remote: Using rake 10.4.2
remote: Using i18n 0.7.0
remote: Using json 1.8.3
remote: Using minitest 5.8.3
remote: Using thread_safe 0.3.5
remote: Using builder 3.2.2
remote: Using erubis 2.7.0
remote: Using rack 1.5.5
remote: Using mime-types 2.99
remote: Using arel 5.0.1.20140414130214
remote: Using execjs 2.6.0
remote: Using bcrypt 3.1.10
remote: Using sass 3.4.20
remote: Using bundler 1.9.7
remote: Using mini_portile2 2.0.0
remote: Using coffee-script-source 1.10.0
remote: Using thor 0.19.1
remote: Using concurrent-ruby 1.0.0
remote: Using country-select 1.1.1
remote: Using gherkin3 3.1.2
remote: Using diff-lcs 1.2.5
remote: Using multi_json 1.11.2
remote: Using multi_test 0.1.2
remote: Using orm_adapter 0.5.0
remote: Using mimemagic 0.3.0
remote: Using pg 0.18.4
remote: Using rails_serve_static_assets 0.0.4
remote: Using rails_stdout_logging 0.0.4
remote: Using tilt 2.0.1
remote: Using rdoc 4.2.1
remote: Using tzinfo 1.2.2
remote: Using mail 2.6.3
remote: Using rack-test 0.6.3
remote: Using warden 1.2.4
remote: Using autoprefixer-rails 6.2.2
remote: Using uglifier 2.7.2
remote: Using nokogiri 1.6.7.1
remote: Using coffee-script 2.4.1
remote: Using sprockets 3.5.2
remote: Using cucumber-core 1.3.1
remote: Using rails_12factor 0.0.3
remote: Using activesupport 4.1.8
remote: Using sdoc 0.4.1
remote: Using bootstrap-sass 3.3.6
remote: Using xpath 2.0.0
remote: Using cucumber 2.1.0
remote: Using actionview 4.1.8
remote: Using activemodel 4.1.8
remote: Using climate_control 0.0.3
remote: Using jbuilder 2.4.0
remote: Using capybara 2.5.0
remote: Using actionpack 4.1.8
remote: Using activerecord 4.1.8
remote: Using cocaine 0.5.8
remote: Using actionmailer 4.1.8
remote: Using railties 4.1.8
remote: Using sprockets-rails 2.3.3
remote: Using simple_form 3.2.1
remote: Using paperclip 4.3.2
remote: Using coffee-rails 4.0.1
remote: Using responders 1.1.2
remote: Using jquery-rails 3.1.4
remote: Using rails-i18n 4.0.8
remote: Using rails 4.1.8
remote: Using sass-rails 5.0.4
remote: Using turbolinks 2.5.3
remote: Using devise 3.5.3
remote: Using cucumber-rails 1.4.0
remote: Bundle complete! 27 Gemfile dependencies, 68 gems now installed.
remote: Gems in the groups development and test were not installed.
remote: Bundled gems are installed into ./vendor/bundle.
remote: Bundle completed (3.99s)
remote: Cleaning up the bundler cache.
remote: -----> Preparing app for Rails asset pipeline
remote: Running: rake assets:precompile
remote: Asset precompilation completed (1.77s)
remote: Cleaning assets
remote: Running: rake assets:clean
remote:
remote: ###### WARNING:
remote: Removing `Gemfile.lock` because it was generated on Windows.
remote: Bundler will do a full resolve so native gems are handled properly.
remote: This may result in unexpected gem versions being used in your app.
remote: In rare occasions Bundler may not be able to resolve your dependencies at all.
remote: https://devcenter.heroku.com/articles/bundler-windows-gemfile
remote:
remote: ###### WARNING:
remote: No Procfile detected, using the default web server (webrick)
remote: https://devcenter.heroku.com/articles/ruby-default-web-server
remote:
remote:
remote: -----> Discovering process types
remote: Procfile declares types -> (none)
remote: Default types for buildpack -> console, rake, web, worker
remote:
remote: -----> Compressing... done, 37.4MB
remote: -----> Launching... done, v38
remote: https://library-online-duofer.herokuapp.com/ deployed to Heroku
remote:
remote: Verifying deploy... done.
I don't know if you've been through the whole process so I guess it won't hurt to detail it :
After you've created a new app on Heroku you should add Postgres Add-on in resources. It will create an environment variable named DATABASE_URL that you can find in settings/config variables. You should add this variable's name in your database.yml as follow :
production:
<<: *default
database: DATABASE_URL
Then you'll push this file, run heroku rake db:migrate, and you should be good to go.
Worth saying your new database on Heroku won't be populate by your development.sqlite3, so in other words you'll start with an empty database.
#FreedomBanana: It is the BookController:
class BooksController < ApplicationController
before_action :set_book, only: [:show, :edit, :update, :destroy]
# GET /books/all
# GET /books/all.json
# GET /books/all.xml
def all
#books = Book.all
end
# GET /books/available
# GET /books/available.json
# GET /books/available.xml
def available
#books = Book.available
end
# GET /books/reserved
# GET /books/reserved.json
# GET /books/reserved.xml
def reserved
#books = Book.reserved
end
# GET /books/1
# GET /books/1.json
# GET /books/1.xml
def show
#comments = #book.comments
#comment = #book.comments.new
end
# GET /books/new
def new
#book = Book.new
end
# GET /books/1/edit
def edit
end
def reserve_it
#ref_book = params[:ref_book]
#book = Book.find(#ref_book)
#book.situation_id = 2
#book.save
redirect_to '/books/available', notice: I18n.t('books.reserved')
end
def render_it
#ref_book = params[:ref_book]
#book = Book.find(#ref_book)
#book.situation_id = 1
#book.save
redirect_to '/books/reserved', notice: I18n.t('books.rendered')
end
# def send_mail
# #me= 'duong.elisabeth#gmail.com'
# ContactMailer.contact_email(#me).deliver
# redirect_to '/contact', notice: I18n.t('Mail_sent')
# end
def delete
#ref_book = params[:ref_book]
#book = Book.find(#ref_book)
#book.destroy
redirect_to '/books/all', notice: I18n.t('books.destroyed')
end
# POST /books
# POST /books.json
def create
#book = Book.create(book_params)
#book.situation_id = 1
respond_to do |format|
if #book.save
format.html { redirect_to #book, notice: I18n.t('books.created') }
format.json { render :show, status: :created, location: #book }
else
format.html { render :new }
format.json { render json: #book.errors, status: :unprocessable_entity }
end
end
end
# PATCH/PUT /books/1
# PATCH/PUT /books/1.json
def update
respond_to do |format|
if #book.update(book_params)
format.html { redirect_to #book, notice: I18n.t('books.updated') }
format.json { render :show, status: :ok, location: #book }
else
format.html { render :edit }
format.json { render json: #book.errors, status: :unprocessable_entity }
end
end
end
# DELETE /books/1
# DELETE /books/1.json
def destroy
#book.destroy
respond_to do |format|
format.html { redirect_to books_url, notice: I18n.t('books.destroyed') }
format.json { head :no_content }
end
end
private
# Use callbacks to share common setup or constraints between actions.
def set_book
#book = Book.find(params[:id])
end
# Never trust parameters from the scary internet, only allow the white list through.
def book_params
params.require(:book).permit(:title, :author, :synopsis, :cover, :note, :situation_id)
end
end
I don't know why but i succeed to resolve the problem.
I just change into the file production.rb the line: config.action_controller.perform_caching = trueto config.action_controller.perform_caching = false
I don't understant but it works now.
Thank you all for your help
Did you complete the following steps while deploying the app to Heroku...!
git push heroku master
heroku run rake db:migrate
For more on deploying an app to Heroku, follow the link:
Put Your App Online With Heroku
You have to pre-compile the assets to make your local files in assets folder to get run in Heroku app, as Heroku wont do it automatically for the assets folder, for more on this process see the given bellow stack overflow thread.
How to load local images in Rail App to Heroku Production App
Related
I'm currently working on a Rails application version Rails 4.2.6 and ruby 2.2.2. I'm trying to run rspec tests, I have versions
rspec-core 3.7.1
- rspec-expectations 3.7.0
- rspec-mocks 3.7.0
- rspec-rails 3.7.2
- rspec-support 3.7.1
When I run the following command bundle exec rspec spec/models/user_spec.rb I get the following error:
An error occurred while loading ./spec/models/user_spec.rb.
Failure/Error: require "rspec/rails"
NameError: uninitialized constant
ActionView::Template::Handlers::ERB::ENCODING_FLAG
Here is my rails_helper.rb
# This file is copied to spec/ when you run 'rails generate rspec:install'
require 'spec_helper'
require "rspec/rails"
require "capybara/rspec"
ENV['RAILS_ENV'] ||= 'test'
require File.expand_path('../../config/environment', __FILE__)
# Prevent database truncation if the environment is production
abort("The Rails environment is running in production mode!") if Rails.env.production?
ActiveRecord::Migration.maintain_test_schema!
Capybara.register_driver :selenium_chrome do |app|
Capybara::Selenium::Driver.new(app, browser: :chrome)
end
Capybara.javascript_driver = :selenium_chrome
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 = false
config.infer_spec_type_from_file_location!
# Filter lines from Rails gems in backtraces.
config.filter_rails_from_backtrace!
config.before(:suite) do
DatabaseCleaner.clean_with(:truncation)
end
config.before(:each) do
DatabaseCleaner.strategy = :transaction
end
config.before(:each, js: true) do
DatabaseCleaner.strategy = :truncation
end
# This block must be here, do not combine with the other `before(:each)` block.
# This makes it so Capybara can see the database.
config.before(:each) do
DatabaseCleaner.start
end
config.after(:each) do
DatabaseCleaner.clean
end
end
Here is the Gemfile:
group :development, :test do
gem 'rspec'
gem 'rspec-rails'
gem 'byebug'
gem 'pry'
gem 'pry-nav'
gem 'pry-stack_explorer'
end
group :test do
gem "capybara"
gem "selenium-webdriver"
end
What happens if you move:
...
ENV['RAILS_ENV'] ||= 'test'
require File.expand_path('../../config/environment', __FILE__)
...
to the beginning of the file?
Im currently working on a Rails 4.2.6 and with RSpec 3.7 version. When I run my test I get the following error:
undefined method `build' for #<RSpec::ExampleGroups::UserName:0x007ff984a99d38>
What is triggering this error is the following code.
require 'rails_helper'
RSpec.describe User, "name" do
#setup
it "returns the email" do
#build
user = build(:user, email: "everlastingwardrobe#example.com")
# excercise and verify
expect(user.email).to eq "everlastingwardrobe#example.com"
end
end
I'm using build instead of create because I dont want to persist data into the database. I am however using factory_bot_rails so I should have access to this method.
Here is my Gemfile:
group :development, :test do
gem 'rspec'
gem 'rspec-rails'
gem 'factory_bot_rails'
gem 'byebug'
gem 'pry'
gem 'pry-nav'
gem 'pry-stack_explorer'
end
group :test do
gem "capybara"
gem "selenium-webdriver"
end
spec_helper.rb
# This file is copied to spec/ when you run 'rails generate rspec:install'
ENV['RAILS_ENV'] ||= 'test'
require File.expand_path('../../config/environment', __FILE__)
require 'spec_helper'
require "rspec/rails"
require "capybara/rspec"
# Prevent database truncation if the environment is production
abort("The Rails environment is running in production mode!") if Rails.env.production?
# Add additional requires below this line. Rails is not loaded until this point!
# Requires supporting ruby files with custom matchers and macros, etc, in
# spec/support/ and its subdirectories. Files matching `spec/**/*_spec.rb` are
# run as spec files by default. This means that files in spec/support that end
# in _spec.rb will both be required and run as specs, causing the specs to be
# run twice. It is recommended that you do not name files matching this glob to
# end with _spec.rb. You can configure this pattern with the --pattern
# option on the command line or in ~/.rspec, .rspec or `.rspec-local`.
#
# The following line is provided for convenience purposes. It has the downside
# of increasing the boot-up time by auto-requiring all files in the support
# directory. Alternatively, in the individual `*_spec.rb` files, manually
# require only the support files necessary.
#
# Dir[Rails.root.join('spec/support/**/*.rb')].each { |f| require f }
# Checks for pending migrations and applies them before tests are run.
# If you are not using ActiveRecord, you can remove this line.
ActiveRecord::Migration.maintain_test_schema!
Capybara.register_driver :selenium_chrome do |app|
Capybara::Selenium::Driver.new(app, browser: :chrome)
end
Capybara.javascript_driver = :selenium_chrome
RSpec.configure do |config|
# Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
config.fixture_path = "#{::Rails.root}/spec/fixtures"
# If you're not using ActiveRecord, or you'd prefer not to run each of your
# examples within a transaction, remove the following line or assign false
# instead of true.
config.use_transactional_fixtures = false
# RSpec Rails can automatically mix in different behaviours to your tests
# based on their file location, for example enabling you to call `get` and
# `post` in specs under `spec/controllers`.
#
# You can disable this behaviour by removing the line below, and instead
# explicitly tag your specs with their type, e.g.:
#
# RSpec.describe UsersController, :type => :controller do
# # ...
# end
#
# The different available types are documented in the features, such as in
# https://relishapp.com/rspec/rspec-rails/docs
config.infer_spec_type_from_file_location!
# Filter lines from Rails gems in backtraces.
config.filter_rails_from_backtrace!
# arbitrary gems may also be filtered via:
# config.filter_gems_from_backtrace("gem name")
# config.before(:suite) do
# DatabaseCleaner.clean_with(:truncation)
# end
#
# config.before(:each) do
# DatabaseCleaner.strategy = :transaction
# end
#
# config.before(:each, js: true) do
# DatabaseCleaner.strategy = :truncation
# end
#
# # This block must be here, do not combine with the other `before(:each)` block.
# # This makes it so Capybara can see the database.
# config.before(:each) do
# DatabaseCleaner.start
# end
#
# config.after(:each) do
# DatabaseCleaner.clean
# end
end
How can I fix this issue, or should I use create instead?
After adding the gem
Create file in spec/support/factory_bot.rb
Add to factory_bot.rb
RSpec.configure do |config|
config.include FactoryBot::Syntax::Methods
end
Add on rails_helper.rb
require 'support/factory_bot'
The build method is part of FactoryGirl or FactoryBot namespace
Why don't you try
FactoryBot.build(:user :email => 'everlastingwardrobe#example.com')
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
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.
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.