rails 3 rails couldn't find file 'twitter/bootstrap' pt2 - ruby-on-rails-3

This is my second post regarding this issue as my webrick server spits out this message. I've had this before and twiddled with the application.css file to get it to work. My rails is 3.1.3 on ruby 1.9.3. The response from rails is couldn't find file 'twitter/bootstrap'
"all" %>
Researching on Google I've followed seyhunak's responses on this issue. Here is my line in the Gemfile, on its own line and not in a group.
gem 'twitter-bootstrap-rails', :git => 'http://github.com/seyhunak/twitter-bootstrap-rails.git'
Here is what's in my application.css.scss:
*= require_self
*= require bootstrap_and_overrides
*= require_tree .
Here's what's in my application.js
//= require jquery
//= require jquery_ujs
//= require twitter/bootstrap
//= require require_tree .
I have done the following commands:
bundle update
rails g bootstrap:install
rails g bootstrap:layout application fixed
touch bootstrap_and_overrides.css.less
rails s
After restarting the server, I still get that error. I'm unable to get past this.
I think I've exhausted all Stack and Google can suggest. What am I overlooking? thanx, sam

After beating myself up over this, I got some Rails devs to look at this problem. My understanding is that Twitter/Bootstrap needs files to be in the vendor directory. The gem would then need to be removed, commented out, so they would not conflict. My app now shows pages that look like the project's homepage. I'm unsure if I've lost the ability to use less to change things. This is my inexperience showing. Thanks for looking.

Moving gem "twitter-bootstrap-rails" out of group :assets
And doing a bundle install worked for me.
Here is some more information
https://github.com/seyhunak/twitter-bootstrap-rails/issues/91

I have similar problem,
I use application.html.haml instead of application.html.erb
using this link:
HTML to Haml
Code is as:
%html
%head
%title Task
= stylesheet_link_tag "application", media: "all", "data-turbolinks-track" => true
= javascript_include_tag "application", "data-turbolinks-track" => true
= csrf_meta_tags
%body
= yield
You Must install Haml gem first:
install haml gem rails

Related

Rails: How to disable turbolinks in Rails 5?

It's a constant headache when dealing with websockets, and it kills my performance in addition to adding bugs. Since ActionCable is the whole reason I upgraded I'd very much like to get rid of it completely.
The following was copied from here. It's for Rails 4, but I believe the steps are the same.
Remove the gem 'turbolinks' line from Gemfile.
Remove the //= require turbolinks from app/assets/javascripts/application.js.
Remove the two "data-turbolinks-track" => true hash key/value pairs from app/views/layouts/application.html.erb.
Edit: As of at least Rails 5 the last step should refer to "data-turbolinks-track" => "reload" as opposed to "data-turbolinks-track" => true. Thanks to #boddhisattva
Edit: As of at least Rails 4.2 you can generate a project without turbolinks to begin with. Just use something like this:
rails new my_app --skip-turbolinks
Removing //= require turbolinks from app/assets/javascripts/application.js seems to have done the trick.
I also removed both turbolinks references in app/views/layouts/application.html.erb
If you are using Webpacker (Rails 5-6)
Delete this line from Gemfile and run bundle:
gem 'turbolinks', '~> 5'
Run yarn remove turbolinks
Delete this line from application pack file app/javascript/packs/application.js:
require("turbolinks").start()
Remove any data-turbolinks data attributes from your html.
Change:
<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %>
<%= javascript_pack_tag 'application', 'data-turbolinks-track': 'reload' %>
to
<%= stylesheet_link_tag 'application', media: 'all' %>
<%= javascript_pack_tag 'application' %>
you can also do it when you create your rails application by using;
rails new app name --skip-turbolinks
Completely removing the turbolinks tags from application.html.erb might break CSS and JS. add this lines instead of the turbolinks if no CSS or JS is loaded:
<%= stylesheet_link_tag "application", media: "all" %>
<%= javascript_include_tag "application" %>

Rails 3 exclude HTML5 jwplayer js in manifest

In my application.js, I have the manifest for external js files as such
//= require jquery
//= require jquery-ui-1.8.17.custom.min
//= require jquery_ujs
//= require jquery-mousewheel.js
//= require jquery-fileupload
//= require jquery-fileupload-ui
//= require_self
//= require bootstrap.min.js
//= require rails.validations
//= require rails.validations.custom
//= require jwplayer
//= require jwplayer.html5
//= require jwplayer-license
When I run my web app in IE8, I get this error:
Message: 'n.sheet.cssRules' is null or not an object
After some searching, I traced the error back to the jwplayer.html5.js file. Is there a way to exclude this file from within application.js when IE8 is detected?
I ran into the exact same issue with the same setup (Rails 3, JWPlayer 6.1.x, etc). For what it's worth, upgrading to JWPlayer 6.2.x didn't resolve the issue
I don't have a solution, but I do have a workaround. I pulled JWPlayer out of my application.js, added <%= yield :javascripts %> to my application.html.erb, and moved the JWPlayer includes to only the view where I needed them:
<% content_for :javascripts do %>
<%= javascript_include_tag "jwplayer" %>
<%= javascript_include_tag "jwplayer.html5" %>
<% end -%>
Note that in my case, I also had to add those files to config.assets.precompile.
Essentially what's happening is that IE8 (and presumably 7) is freaking out if there's no instance of JWPlayer on the page. The ideal fix would actually be for JWPlayer itself to check if that's the case instead of letting IE throw an error, but until they fix it on their end, this at least gets things working.
It's frustrating and far from an ideal solution, but it worked in my application.
I was struggling with this too. I did some work on the jwplayer-rails gem. I am still waiting on my pull request to go through. For now follow the info in this readme to get it up and running. Read more on my answer here.

rails activeadmin errors rspec

my database is MongoDB and I use ActiveAdmin.
before i add gem 'activeadmin-mongoid', :git => 'git://github.com/simplybusiness/activeadmin-mongoid.git' rspec pass every test with mongoDB, but after that rspec get an errors
ActiveRecord::ConnectionNotEstablished
file config/application.rb I repalce
require all with
require "action_controller/railtie"
require "action_mailer/railtie"
require "active_resource/railtie"
require "sprockets/railtie"
I removed any activerecord config in folder config . I follow that link
sorry about my bad english.
Any help would be appreciated. Thanks!

How do I make gemspec dependencies autoload in a Rails 3 app, using a Gemfile

I have a Rails 3 app that I am turning into a Rails engine / gem.
This engine has some gem dependencies that I have put inside it's .gemspec file.
I have created a new 'parent' Rails 3 app, and I would like to add my engine gem to the Gemfile and have the gem's dependencies automatically 'loaded', but this does not work for me! bundle install installs the gem dependencies fine, but when I start the server, the app crashes because they are not loaded.
For example, my engine's gemspec contains these lines:
s.add_runtime_dependency(%q<rails>, ["= 3.0.7"])
s.add_runtime_dependency(%q<acts_as_commentable>, [">= 3.0.1"])
s.add_runtime_dependency(%q<haml>, [">= 3.1.1"])
.. and the parent Rails 3 application has these lines in its Gemfile:
source 'http://rubygems.org'
gem 'my_engine', :path => "~/src/gems/my_engine"
But I get the following error:
undefined local variable or method `acts_as_commentable'
from /home/user/src/gems/my_engine/app/models/account.rb:66:in `<class:Account>'
But if I add gem 'acts_as_commentable', '>= 3.0.1' to the Gemfile of the parent Rails 3 app, then the gem is loaded and the error disappears.
I am using Rails 3.0.8.
Does anyone have any suggestions? Do I need to change something about the way my engine is loading?
During main Rails app boot, Bundler will only require dependencies directly listed in the Gemfile but not any sub-dependencies. It's your library's/Engine's responsibility to require its dependencies when it itself gets required. You can do so using initializers in your Railtie.
class MyRailtie < Rails::Railtie
initializer "require stuff" do
require "stuff"
end
end
In our Rails Engine we used a small trick to require dependencies automatically. Unfortunately you can't specify whether or not they should load in the .gemspec, which would allow for greater control.
Gem.loaded_specs["our_rails_engine"].dependencies.each do |d|
begin
require d.name
rescue LoadError => le
# Put exceptions here.
raise le if d.name !~ /factory_girl_rails/
end
end
I'm looking at Spree (the superhero of Rails Engines!), and they do this in spree_core-0.60.1/lib/spree_core.rb:
require "rails/all"
require 'state_machine'
require 'paperclip'
require 'stringex'
require 'will_paginate'
require 'nested_set'
require 'acts_as_list'
require 'resource_controller'
require 'active_merchant'
require "meta_search"
require "find_by_param"
So the answer is that within your gem, you have to require all of it's gem dependencies one by one. Well, that's how I will do it for now. But please comment if this ever changes in the future.
Seems it don't work, i create a host project and a sub-project with rails 3 engine.
Added the gem to engine's gemspec
s.add_dependency 'simple_form'
then added the require to engine_name.rb like below
require 'simple_form'
But if delete the line [gem 'simple_form'] in host project's Gemfile, it will show undefined immediatly

rails assets path

I have in
<link href="/assets/application.css" media="screen" rel="stylesheet" type="text/css" />
<script src="/assets/application.js" type="text/javascript"></script>
but when I go to http://localhost:3000/assets/application.css
Routing Error
No route matches [GET] "/assets/application.css"
P.S. Rails 3.1.0.rc4, ruby 1.8.7
Seems Sprockets / Rails 3.1 were acting up for me w/ ruby 1.9.2-p180 ... updating to Ruby-1.9.2-p290 seemed to stop the issue.
Maybe not related to your issue... but useful for anyone else having that issue using those versions of Rails & Ruby.
I found that I had something similar going on after updating to Rails 3.1 this evening. I was working on a project that didn't use ActiveRecord, so I had a modified my application.rb to exclude it. The line that usually reads require 'rails/all' to only include the parts I needed, like this:
require "action_controller/railtie"
require "action_mailer/railtie"
require "active_resource/railtie"
require "rails/test_unit/railtie"
This list has changed in Rails 3.1 to include Sprockets, the core component to making the asset pipeline work. I got the asset pipeline serving the serving content as expected by adding this line to the bottom of the list:
require "sprockets/railtie"
After restarting, /assets/application.js and other assets began working as expected.
Note: if you have a custom setup like this, be sure to open the railties gem and look at the contents of lib/rails/all.rb which may have changed (as in this case).
Your scripts and styles will be loaded from the public folder. Drop the assets folder under public and you should be good to go.
In the application layout file, if you have
<%= stylesheet_link_tag "/assets/application" %>
which gives
No route matches [GET] "/assets/application.css"
TRY changing it to
<%= stylesheet_link_tag "application" %>
I had to add the following line in application.rb:
config.assets.enabled = true
in bottom of class Application < Rails::Application