./bin/rails css:install:bootstrap fails - ruby-on-rails

./bin/rails css:install:bootstrap is failing.
rails aborted!
NoMethodError: undefined method `assets' for #<Rails::Application::Configuration:0x000000010afa4118 #root=#<Pathname:~/Documents/rails_project>
What is going on.
I've had trouble running commands like this with spaces in the path, but I don't have spaces in this case.

config.assets comes from asset pipeline:
sprockets-rails
https://github.com/rails/sprockets-rails/blob/v3.4.2/lib/sprockets/railtie.rb#L99
or propshaft
https://github.com/rails/propshaft/blob/v0.6.4/lib/propshaft/railtie.rb#L6
There was config.assets in rails itself, but it was removed in rails 5.
In rails 6 and before, sprockets-rails was a dependency so you would get config.assets automatically.
In rails 7 sprockets-rails became optional and you must have gem "sprockets-rails" or gem "propshaft" in your Gemfile.
https://guides.rubyonrails.org/upgrading_ruby_on_rails.html#sprockets-is-now-an-optional-dependency

Related

What's the replacement for acts_as_commentable in Rails 6, Ruby 3.0.2?

I upgraded our app to Rails 6.1.4.4 and Ruby 3.0.2. I have this old gem
gem 'acts_as_commentable'
Locked at version 4.0.2. The gem does not appear to be supported anymore, which is a shame because when I start up my app or console, I now get this error
$ rails c
Your Gemfile lists the gem rspec-rails (>= 0) more than once.
You should probably keep only one of them.
Remove any duplicate entries and specify the gem only once.
While it's not a problem now, it could cause errors if you change the version of one of them later.
/Users/myuser/.rvm/gems/ruby-3.0.2/gems/hash_dot-2.5.0/lib/hash.rb:19:in `method_missing': undefined method `arity' for {:as=>:commentable, :dependent=>:destroy}:Hash (NoMethodError)
from /Users/myuser/.rvm/gems/ruby-3.0.2/gems/activerecord-6.1.4.4/lib/active_record/associations/builder/association.rb:53:in `build_scope'
from /Users/myuser/.rvm/gems/ruby-3.0.2/gems/activerecord-6.1.4.4/lib/active_record/associations/builder/association.rb:47:in `create_reflection'
from /Users/myuser/.rvm/gems/ruby-3.0.2/gems/activerecord-6.1.4.4/lib/active_record/associations/builder/association.rb:32:in `build'
from /Users/myuser/.rvm/gems/ruby-3.0.2/gems/activerecord-6.1.4.4/lib/active_record/associations.rb:1458:in `has_many'
from /Users/myuser/.rvm/gems/ruby-3.0.2/gems/acts_as_commentable-4.0.2/lib/commentable_methods.rb:58:in `acts_as_commentable'
…
Is there any simple replacement for this gem or way to monkey-patch this error so I can start up the app?
Looking over the forks, I found this one that appears to work for me using Rails 6.0.6 and Ruby 3.0.5.
https://github.com/alazycoder101/acts_as_commentable.git
I have not tested it extensively yet, but at least the basic functionality seems to be working for me. Hope this helps.
For clarity, to use that fork you would use the following line in your Gemfile:
gem 'acts_as_commentable', git: 'https://github.com/alazycoder101/acts_as_commentable.git'

rails6 app: minitest failing with ActionView::Template::Error: uninitialized constant

A bit of a puzzler - I've got an app using a very simple gem I wrote (UIAvatars) to generate a URL to an Avatar API. This demonstrably working in my Development rails app (the Avatar is displayed with no issues) but when I try to run my controller tests it causes errors like so:
Error:
InitiativesControllerTest#test_should_get_new:
ActionView::Template::Error: uninitialized constant ProfilesHelper::UIAvatars
app/helpers/profiles_helper.rb:17:in `profile_image_link_for'
app/views/layouts/_header.html.erb:62
app/views/layouts/application.html.erb:23
test/controllers/initiatives_controller_test.rb:15:in \`block in <class:InitiativesControllerTest>'
The method in profiles_helper is:
def profile_image_link_for(profile, **options)
image_tag(
UIAvatars.generateURL(name: profile.full_name, size: "128", background: "random"),
options
).html_safe
end
bundle says it is installed:
% bundle info ui_avatars
* ui_avatars (0.0.1)
Summary: Generate avatars with initials from names using https://ui-avatars.com
Homepage: https://rubygems.org/gems/ui_avatars
Path: /Users/thatsme/.rvm/gems/ruby-2.6.6/gems/ui_avatars-0.0.1
it's in my Gemfile in the default group
gem 'ui_avatars'
Any idea what could be causing this problem?
Answer is that .ruby-version had a different version of ruby (2.6.7) than I was actually using (2.6.6) and so ruby could not find the gem installed in the expected path when running minitest.
(why it still worked in rails is a question for another day).

Bootstrap Devise Cancan Rails - Rspec Failure

I just installed Rails3 Bootstrap Device Cancan in my local machine and ran rake spec but I'm getting all test failures with below error in common:
undefined local variable or method 'postgresql_version' for #<ActiveRecord::ConnectionAdaptors::SQLite3Adaptor:0x489dff8>
I'm not sure why I'm getting this since I followed the instructions on https://github.com/RailsApps/rails3-bootstrap-devise-cancan carefully.
I'm currently running this on Windows 8 and used Bitnami RubyStack to run CMD
I ran into the same problem and this is how I resolved it.
It looks like there is a problem with version 1.1.0 of database_cleaner. See "database_cleaner >= 1.1.0 is broken for SQLite" (https://github.com/gregbell/active_admin/issues/2388). I updated my Gemfile to set
gem 'database_cleaner', '< 1.1.0'
then ran "bundle install" and after it completed, "rake spec" ran cleanly.
Double-check your database.yml. Refer to Configuring Rails Applications, Section 3.12, Configuring a Database.
Did you intend to use sqlite3? Is sqlite3 in your Gemfile? Naturally, SQLite3Adaptor will not respond to postgresql_version! Can you include a few more lines of the stack trace?
I doubt this has anything to do with devise or cancan.

Rails emits warning: "Rack::File headers parameter replaces cache_control after Rack 1.5"

I've recently upgraded my Rails to v3.2. The server starts and works, however I'm noticing the following warning:
Rack::File headers parameter replaces cache_control after Rack 1.5.
In my development.rb I have the following configuration for cache control:
config.static_cache_control = "public, max-age=36000"
What does the warning mean and what should I do to address it?
The warning is caused by a call from within Rails itself. The warning has been fixed in Rails 3.2.13.
You have to upgrade Rake file. This issue occurred in Rails 3.2.12 but solved in Rails 3.2.13 to solve this issue. You have to delete your Gemfile.lock from your app (NOTE: As you may get error something like "Rakefile locked", Take backup of Gemfile.lock file if this solution won't help).
Open your Gemfile and find gem 'rails', '3.2.12' and replace it with gem 'rails', '3.2.13' then in your terminal run bundle install. Now you will not get this warning.

upgraded rails 3 app rake db:reset error

I upgraded my rails 2.3.8 app to rails 3. when I run the rake db:reset command, it returns the following error
rake aborted!
test-unit is not part of the bundle. Add it to Gemfile.
/Users/Shenario/Desktop/stack24/Rakefile:7:in `'
(See full trace by running task with --trace)
i'm new to rails, and wud be glad if you guys out ther coud help me! thanks!
the trace --
rake aborted!
test-unit is not part of the bundle. Add it to Gemfile.
/Users/Shenario/.rvm/gems/ruby-1.9.2-p136/gems/bundler-1.0.7/lib/bundler/shared_helpers.rb:102:in block in cripple_rubygems'
/Users/Shenario/Desktop/stack24/lib/tasks/rspec.rake:1:in'
/Users/Shenario/.rvm/gems/ruby-1.9.2-p136/gems/railties-3.0.3/lib/rails/engine.rb:131:in load'
/Users/Shenario/.rvm/gems/ruby-1.9.2-p136/gems/railties-3.0.3/lib/rails/engine.rb:131:inblock in load_tasks'
/Users/Shenario/.rvm/gems/ruby-1.9.2-p136/gems/railties-3.0.3/lib/rails/engine.rb:131:in each'
/Users/Shenario/.rvm/gems/ruby-1.9.2-p136/gems/railties-3.0.3/lib/rails/engine.rb:131:inload_tasks'
/Users/Shenario/.rvm/gems/ruby-1.9.2-p136/gems/railties-3.0.3/lib/rails/application.rb:141:in load_tasks'
/Users/Shenario/.rvm/gems/ruby-1.9.2-p136/gems/railties-3.0.3/lib/rails/application.rb:77:inmethod_missing'
/Users/Shenario/Desktop/stack24/Rakefile:7:in <top (required)>'
/Users/Shenario/.rvm/gems/ruby-1.9.2-p136/gems/rake-0.8.7/lib/rake.rb:2383:inload'
/Users/Shenario/.rvm/gems/ruby-1.9.2-p136/gems/rake-0.8.7/lib/rake.rb:2383:in raw_load_rakefile'
/Users/Shenario/.rvm/gems/ruby-1.9.2-p136/gems/rake-0.8.7/lib/rake.rb:2017:inblock in load_rakefile'
/Users/Shenario/.rvm/gems/ruby-1.9.2-p136/gems/rake-0.8.7/lib/rake.rb:2068:in standard_exception_handling'
/Users/Shenario/.rvm/gems/ruby-1.9.2-p136/gems/rake-0.8.7/lib/rake.rb:2016:inload_rakefile'
/Users/Shenario/.rvm/gems/ruby-1.9.2-p136/gems/rake-0.8.7/lib/rake.rb:2000:in block in run'
/Users/Shenario/.rvm/gems/ruby-1.9.2-p136/gems/rake-0.8.7/lib/rake.rb:2068:instandard_exception_handling'
/Users/Shenario/.rvm/gems/ruby-1.9.2-p136/gems/rake-0.8.7/lib/rake.rb:1998:in run'
/Users/Shenario/.rvm/gems/ruby-1.9.2-p136/gems/rake-0.8.7/bin/rake:31:in'
/Users/Shenario/.rvm/gems/ruby-1.9.2-p136/bin/rake:19:in load'
/Users/Shenario/.rvm/gems/ruby-1.9.2-p136/bin/rake:19:in'
After searching for "test-unit", found this:
gem 'test-unit', '2.0.7' if RUBY_VERSION.to_f >= 1.9
in lib/tasks/rspec.rake
I suspected it was caused by me copying the whole lib folder from older rails version to this new one.
Solution: removed that file, then things seem to work fine after.
Basically I suggest you look at lib/tasks and see if there are rake tasks that are incompatible with rails 3.
you must have at least
gem "rails", "~> 3.0.3"
in your Gemfile, then remove Gemfile.lock (if any) and run:
bundle check
if you need some missing gems, run:
bundle install
bundler will install all required gems at least for rails 3.0.3, including test-unit gem. btw remember that a migration from rails 2.3.x to 3.0.x in most cases requires some code changes.
Add this to your Gemfile (replacing VERSION with your required version number).
gem 'test-unit', 'VERSION', :platform => :ruby_19
For Rails 2.3.11, I needed version 1.2.3 of the test-unit gem.

Resources