How to get bootstrap helpers using Rails 5 and Bootstrap 4 - asset-pipeline

I'm working on an application upgrade from rails 4.2 (with bootstrap 3) to rails 5 (bootstrap 4.0.0.alpha3.1).
I'm using the official bootstrap-rubygem https://github.com/twbs/bootstrap-rubygem and I'm following the steps on the documentation, but the problem I have is the absence of the classical bootstrap helpers. I.e.: menu_group, nav_bar, menu_item, dropdown_divider, etc...
Is there any way to get these helpers back as on bootstrap3?
The relevant configuration I have, regarding this issue, is:
Gemfile:
gem 'rails', '~> 5.0.0'
gem 'sass-rails', '~> 5.0'
gem 'jquery-rails'
gem 'turbolinks', '~> 5'
gem 'bootstrap', '~> 4.0.0.alpha3.1'
application.js:
//= require jquery
//= require jquery_ujs
//= require turbolinks
//= require bootstrap-sprockets
//= require_tree .
application.scss:
#import "bootstrap";

This is due to bootstrap framework has large number of changes.

Related

'Bundler.require' requiring all gems?

Trying to figure out Ruby's Bundler library. My understanding is we can require only certain groups, but my setup seems to be loading gems specified in other groups as well.
Gemfile
source 'https://rubygems.org'
# Specify your gem's dependencies in apple.gemspec
gemspec
group :production do
gem 'mail'
gem 'bundler'
gem 'pry'
gem 'commander'
gem 'fastlane'
gem 'spaceship'
gem 'highline'
gem 'terminal-table'
gem 'clipboard'
gem 'date'
gem 'mysql2'
gem 'fileutils'
gem 'redis'
gem 'json'
gem 'logger'
gem 'jira-ruby', :require => 'jira-ruby'
end
group :jenkins do
gem 'terminal-table'
gem 'pry'
gem 'mail'
gem 'jira-ruby'
gem 'spaceship'
end
test.rb
require 'pry'
binding.pry
require 'rubygems'
require 'bundler/setup'
Bundler.require(:jenkins) # I want this step to require only gems listed under 'jenkins' group in `Gemfile`.
...
When I run the code, it seems Bundler.require(:jenkins) step seems to be requiring all gems specified in Gemfile,
I am still in the process of understanding Bundler, pardon me if the question I asked is too obvious. Does anyone know how to only load the gems from bundler groups? Thanks in advance!!
This is kind of confusing, but as far as I can tell from using it myself, it only requires the gems in the given group even though it lists all of them.
It's pretty easy to see this for yourself, just try using one from the production group
Bundler.require(:jenkins)
Date.new # Should error
Really it seems like you may have noticed this yourself, but you just didn't realize.. If it was including all of them you wouldn't have needed to require pry in test.rb :)

rails4 + bootstrap displays the error as "variable #zindex-modal-background is undefined"

I'm trying to make the project that use bootstrap on rails4.1.6.
Here is gemfile:
gem 'therubyracer'
gem 'less-rails'
gem 'twitter-bootswatch-rails', '~> 3.1.1'
gem 'twitter-bootswatch-rails-helpers'
$ bundle install was successful.
and settings of bootswatch
$ rails g bootswatch:install cerulean
$ rails g bootswatch:import cerulean
$ rails g bootswatch:layout cerulean
app/assets/stylesheet/application.css
*= require cerulean/loader
*= require cerulean/bootswatch
app/assets/javascript/application.js
//= require cerulean/loader
//= require cerulean/bootswatch
but $ rails s and when I viewed the site , appears the following error:
variable #zindex-modal-background is undefined
(in /Users/ko2ic/sample/app/assets/stylesheets/cerulean/loader.css.less)
How do you solve it doing?
It was resolved by adding the next code:
assets/stylesheets/cerulean/variables.less
#zindex-modal-background: 0;
reference:
http://github.com/scottvrosenthal/twitter-bootswatch-rails/issues/30

Rails 4. Breakpoint gem path error. File to import not found or unreadable: breakpoint

Problem:
I have a basic Rails 4.0.10 project where I want to use breakpoint for media queries.
My Gemfile:
source 'https://rubygems.org'
gem 'rails', '4.0.10'
gem 'sqlite3'
gem 'httparty'
gem 'requirejs-rails'
gem "github_api"
gem "breakpoint", "~>2.4.0"
gem 'uglifier', '>= 1.3.0'
gem 'jquery-rails'
gem 'jbuilder', '~> 1.2'
group :doc do
gem 'sdoc', require: false
end
When I am requiring breakpoint in my sass stylesheets it throws:
Sass::SyntaxError in Stats#index
Showing /home/action/workspace/sofapp/sofa/app/views/layouts/application.html.erb where line #7 raised:
File to import not found or unreadable: breakpoint.
Load paths:
/home/action/workspace/sofapp/sofa/app/assets/fonts
/home/action/workspace/sofapp/sofa/app/assets/images
/home/action/workspace/sofapp/sofa/app/assets/javascripts
/home/action/workspace/sofapp/sofa/app/assets/stylesheets
/home/action/workspace/sofapp/sofa/vendor/assets/javascripts
/home/action/workspace/sofapp/sofa/vendor/assets/stylesheets
/home/action/.rvm/gems/ruby-2.0.0-p247/gems/jquery-rails-3.1.2/vendor/assets/javascripts
/home/action/.rvm/gems/ruby-2.0.0-p247/gems/requirejs-rails-0.9.5/vendor/assets/javascripts
/home/action/.rvm/gems/ruby-2.0.0-p247/gems/breakpoint-2.4.6/lib/stylesheets
(in /home/action/workspace/sofapp/sofa/app/assets/stylesheets/main.scss:5)
As you can see from error Sass cannot find right path to load breakpoint. I have looked to the last path and find out that directory /home/action/.rvm/gems/ruby-2.0.0-p247/gems/breakpoint-2.4.6/lib/stylesheets doesn't exist, instead we have /home/action/.rvm/gems/ruby-2.0.0-p247/gems/breakpoint-2.4.6/stylesheets.
Question:
Should I configure asset-pipeline to include the right path for breakpoint or there is some other issue?

Why can't Padrino find my rake tasks?

I just upgraded Padrino from version 0.10.5 to 0.12.1 and now none of my Rake tasks work anymore.
A simple case I just added:
# PROJECT_ROOT/lib/tasks/example_task.rake
task :example_task do
puts "Is this working?"
end
Running rake example_task gives:
rake aborted!
Don't know how to build task 'example_task'
Running padrino rake example_task gives:
=> Executing Rake example_task ...
/Users/george/.rvm/rubies/ruby-2.1.0/lib/ruby/2.1.0/rake/task_manager.rb:49:in `[]': Don't know how to build task 'example_task' (RuntimeError)
Padrino's docs say that Padrino should automatically detect any *.rake files in lib/tasks, and these worked before I upgraded Padrino. What's the problem?
My Gemfile:
source 'https://rubygems.org'
ruby '2.1.0'
gem 'rake'
gem 'unicorn'
gem 'rack_hoptoad', require: 'rack/hoptoad'
gem 'haml'
gem 'bson_ext'
gem 'mongo'
gem 'mongoid', '~> 3.1.6'
gem 'httparty'
group :development, :test do
gem 'debugger'
gem 'fabrication', '~> 1.3.1'
gem 'zippy'
gem 'rubyzip', '~> 0.9.9'
end
group :test do
gem 'mocha', '~> 0.10.4'
gem 'rspec', '~> 2.8.0'
gem 'capybara', '~> 1.1.2'
gem 'launchy'
gem 'cucumber', '~> 1.1.8'
end
gem 'tilt', '~> 1.4.1'
gem 'padrino', '~> 0.12.1'
gem 'padrino-cookies', '~> 0.1.2'
According to bundle show rake, I'm using rake version 10.3.1.
What am I doing wrong?
Well, that was a waste of a bounty.
I opened an issue on Github and got an answer there. I needed to make the following changes to the top of config/boot.rb... (this is taken from the output of git diff, so note that lines which start with - were removed and lines which start with + were added.)
-begin
- # Require the preresolved locked set of gems.
- require File.expand_path('../../.bundle/environment', __FILE__)
-rescue LoadError
- # Fallback on doing the resolve at runtime.
- require 'rubygems'
- require 'bundler'
- Bundler.setup
-end
-
+require 'rubygems' unless defined?(Gem)
+require 'bundler/setup'
And add these lines to my Rakefile:
+require 'bundler/setup'
+require 'padrino-core/cli/rake'
+
+PadrinoTasks.use(:database)
+PadrinoTasks.use(:mongoid)
+PadrinoTasks.init
Now my rake tasks work as normal. Yay!
Use this pattern and it will work with new version of Padrino without any core changes:
# ./lib/tasks/seed_fonts.rake
namespace :fonts do
desc "Seen the fonts into database table db.fonts"
task :seed_fonts => :environment do
# Do your thing ...
end
end

Asset pipeline in a Rails 3.2.11 app works fine with Ruby 1.9.3 but stops working in Ruby 2.0.0

My asset pipeline was working fine in Ruby 1.9.3. When I upgrade to 2.0.0 It stops working.
In Gemfile:
gem 'jquery-rails'
In application.js file:
//= require jquery
//= require jquery_ujs
//= require bootstrap-affix
//= require bootstrap-alert
...
//= require jquery_nested_form
//= require sitengine.js
//= require_tree .
Result from .../assets/application.js in browser:
//= require jquery
//= require jquery_ujs
//= require bootstrap-affix
//= require bootstrap-alert
...
//= require jquery_nested_form
//= require my_app.js
//= require_tree .
;
Two questions:
Have you experienced this? If you have, would love to have a comment from you.
Have you found a solution? (Thanks in advance for your answer.)
Thanks!
I updated all my gems with bundle update and that did the trick.
No idea why, probably some gems were updated for ruby 2.

Resources