I've been seeing this for a while, and have finally got round to finding a solution.
In the project `Gemfile`, remove the reference to `sass-rails` and replace with `sassc`.
Sigh. It took more than two minutes to find the fix, so logging it here
Monday, 22 October 2018
Saturday, 7 July 2018
NameError: uninitialized constant RailsERD
This has been an occasional annoyance when setting up new Rails projects with the rails-erd gem.
The documentation for the gem is to add
into the Gemfile, and then run rails g erd:install to add the hook to run when a rails db:migrate is carried out.
I found that this creates /lib/tasks/auto_generate_diagram.rake containing
One solution is to remove the :require=>false from the Gemfile, but apparently this may have an impact on efficiency rails erd issue 282.
I tried a slightly different approach, and changed /lib/tasks/auto_generate_diagram.rake to require the gem.
The documentation for the gem is to add
gem 'rails-erd', :require=>false
into the Gemfile, and then run rails g erd:install to add the hook to run when a rails db:migrate is carried out.
I found that this creates /lib/tasks/auto_generate_diagram.rake containing
if Rails.env.development? RailsERD.load_tasks end
One solution is to remove the :require=>false from the Gemfile, but apparently this may have an impact on efficiency rails erd issue 282.
I tried a slightly different approach, and changed /lib/tasks/auto_generate_diagram.rake to require the gem.
if Rails.env.development? require 'rails-erd' RailsERD.load_tasks end
Sunday, 21 January 2018
Publishing Rails 5 apps to heroku
When attempting to migrate the database, I was getting errors with the following two messages
Gem::LoadError: Specified 'postgresql' for database adapter, but the gem is not loaded. Add `gem 'pg'` to your Gemfile (and ensure its version is at the minimum required by ActiveRecord).
Gem::LoadError: can't activate pg (~> 0.18), already activated pg-1.0.0. Make sure all dependencies are added to Gemfile.
The second one turned out to be the main issue.
A solution was found in a rails issue 31669, briefly
My solution was to change the Gemfile reference to
And the migration succeeded. Now to apply the issue to the other app I was looking at yesterday...
Gem::LoadError: Specified 'postgresql' for database adapter, but the gem is not loaded. Add `gem 'pg'` to your Gemfile (and ensure its version is at the minimum required by ActiveRecord).
Gem::LoadError: can't activate pg (~> 0.18), already activated pg-1.0.0. Make sure all dependencies are added to Gemfile.
The second one turned out to be the main issue.
A solution was found in a rails issue 31669, briefly
Thank you for the issue. Rails still don't support pg 1.0.
My solution was to change the Gemfile reference to
group :production do
gem 'pg', '~> 0.18'
gem 'rails_12factor'
end
Rails 5 and optional has_many relationships
This is a continuation in the random notes from attempting to learn Ruby on Rails.
Todays' rambling is to do with having an optional relationship between two tables.
I am building an application to help me track fuel usage, and was wanting to have a relationship set between Users and Vehicles, based on the diagram.
The spec tests were failing, because the User:Vehicle relationship was mandatory.
The issue appears to be that Rails 5 has made the belongs_to relationship required (as found in the answer to a StackOverflow question).
The solution seems relatively simple, add the optional link to the relationship:
Todays' rambling is to do with having an optional relationship between two tables.
![]() |
erd from project |
I am building an application to help me track fuel usage, and was wanting to have a relationship set between Users and Vehicles, based on the diagram.
The spec tests were failing, because the User:Vehicle relationship was mandatory.
The issue appears to be that Rails 5 has made the belongs_to relationship required (as found in the answer to a StackOverflow question).
The solution seems relatively simple, add the optional link to the relationship:
belongs_to :user, optional: true
My tests are all passing again. For now.
Saturday, 4 November 2017
[Solved] Deprecation warnings Devise::TestHelpers
Another entry in the series of 'notes to myself' here.
A simple fix for the Deprecation warning saying that Devise::TestHelpers will be removed.
The fix is to replace the
Unlike many of the suggested solutions, I don't have the devise configuration in the rails_helper file.
I have a separate set of helper functions, and the relevant location is
You can stop reading now and go do something more productive instead.
A simple fix for the Deprecation warning saying that Devise::TestHelpers will be removed.
The fix is to replace the
config.include Devise::Test::Helpers, :type => :controller
with
config.include Devise::Test::ControllerHelpers, :type => :controller
in spec/rails_helper.rb.Unlike many of the suggested solutions, I don't have the devise configuration in the rails_helper file.
I have a separate set of helper functions, and the relevant location is
spec/support/devise.rb.
RSpec.configure do |config|
config.include Devise::Test::ControllerHelpers, :type => :controller
end
You can stop reading now and go do something more productive instead.
Thursday, 19 January 2017
RSpec failing after a new Rails Composer project
RSpec issues
Addrequire 'rails_helper.rb'
into the spec files to allow the tests to run as expected.
spec/features/visitors/sign_up_spec.rb
The minimum password length is set to be 6 characters, but the 'expected fail' password was set to 'please', causing the test to fail.Changed password to 'short' and test passes.
spec/features/users/sign_in_spec.rb
The tests were looking for an authentication_key of 'email'. Changed to 'Email' to match the results from Devise.Tuesday, 10 January 2017
Getting Puma to listen for all hosts with the Guardfile
This has been bugging me for a while, and I've finally had time to track down how to configure Guardfile in order to have Puma listen to all ip addresses.
Adding the :host => '0.0.0.0' gets puma to listen for all addresses.
guard 'rails', :host => '0.0.0.0' do watch('Gemfile.lock') watch(%r{^(config|lib)/.*}) end
Adding the :host => '0.0.0.0' gets puma to listen for all addresses.
Subscribe to:
Posts (Atom)