Can't access to bootstrap methods when including bootstrap via application.js - ruby-on-rails-3

First of all, my gemfile
gem 'mysql2'
gem 'json'
gem 'jquery-rails'
gem 'dynamic_form'
gem 'haml-rails'
gem 'geocoder'
gem 'delayed_job_active_record'
gem 'daemons'
gem 'pry'
gem 'debugger'
gem 'unicorn'
gem 'rest-client'
# Gems used only for assets and not required
# in production environments by default.
group :assets do
gem 'sass-rails', '~> 3.2.3'
gem 'coffee-rails', '~> 3.2.1'
gem 'anjlab-bootstrap-rails', '>= 2.1', :require => 'bootstrap-rails'
gem 'therubyracer', :platforms => :ruby
gem 'uglifier', '>= 1.0.3'
end
When I have this manifest in my application.js
//= require jquery
//= require jquery_ujs
//= require twitter/bootstrap
//= require_tree .
if I declare an input with the proper attributes, like this
<input autocomplete="off" data-provide="typeahead" data-source="['Alicante','Albacete']" size="30" type="text">
it works like magic, but I can't do this in my own js
$('#my_input').typeahead()
// => TypeError: Object [object Object] has no method 'typeahead'
However, if I remove bootstrap from the manifest and I include it my layout explicitly
= javascript_include_tag "application", "bootstrap.min"
both ways work.
Can anyone explain me why? Maybe the uglifier of the asset pipeline is namespacing bootstrap functions? How fix it?

Use //= require twitter/bootstrap
https://github.com/anjlab/bootstrap-rails
Edit:
Which gem are you using? twitter-bootstrap-rails, bootstrap-rails or something else?
if using twitter-bootstrap-rails then did you already call rails generate bootstrap:install to set it up?
Does changing the order makes a difference? Try it like this
//= require jquery_ujs
//= require jquery
//= require twitter/bootstrap
//= require_tree .

I've just solved the problem.
It seems that this behavior happens when Bootstrap is being loaded twice (no idea why).
I can't say why that happened, maybe because I tried a couple gems of Bootstrap, but there was a problem with my auto-compiled assets in /public that are generated in production environment.
I run rake assets:clear (task provided by github.com/anjlab/bootstrap-rails) y all works fine again.

Related

issue with mercury rails gem

I was working on a blog app so I want to implemant mercury-rails gem into it, i tried and i got it the tool bar but i was unable to edit any content from my show page
even after everything i am using with the foundation front end framework
<p><span id="page_content class="mercury-region" data-type="editable">
<%=raw #article.content %></span></p>
<h5><span data-type="editable"><%= #article.title %></span></h5>
this is my gem file
# Gems used only for assets and not required
# in production environments by default.
group :assets do
gem 'sass-rails', '~> 3.2.3'
gem 'coffee-rails', '~> 3.2.1'
gem 'zurb-foundation'
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
# gem 'therubyracer', :platforms => :ruby
gem 'uglifier', '>= 1.0.3'
end
gem 'jquery-rails'
# To use ActiveModel has_secure_password
# gem 'bcrypt-ruby', '~> 3.0.0'
# To use Jbuilder templates for JSON
# gem 'jbuilder'
# Use unicorn as the app server
# gem 'unicorn'
# Deploy with Capistrano
# gem 'capistrano'
# To use debugger
# gem 'debugger'
gem 'simple_form'
gem 'friendly_id'
gem 'devise'
gem "rmagick"
gem "carrierwave"
gem "mercury-rails"
By the looks of things you've followed the old railscast. The mercury-rails projects updates quite frequently.
The problem lies in your attributes on the span tag. You can safely remove the class="mercury-region"
You will also need to change data-type="editable" to data-mercury="full".
See the different edit types (defined in the data-mercury attribute) on the github page: https://github.com/jejacks0n/mercury#region-types
I hope that helps!

Sprockets::FileNotFound when using select2 gem with Rails 3.2.8

I am trying to test a sample Rails app to use select2 gem. I have install the gem following select2-rails.
But, unfortunately I am getting the following error :
Sprockets::FileNotFound in Home#index
Showing /Users/Rakib/Desktop/Development/TEST_PROJECTS/selecttest/app/views/layouts/application.html.erb where line #5 raised:
couldn't find file 'select2'
(in /Users/Rakib/Desktop/Development/TEST_PROJECTS/selecttest/app/assets/stylesheets/application.css:14)
Extracted source (around line #5):
2: <html>
3: <head>
4: <title>Selecttest</title>
5: <%= stylesheet_link_tag "application", :media => "all" %>
6: <%= javascript_include_tag "application" %>
7: <%= csrf_meta_tags %>
8: </head>
Rails.root: /Users/Rakib/Desktop/Development/TEST_PROJECTS/selecttest
My Gemfile is :
source 'https://rubygems.org'
gem 'rails', '3.2.8'
gem 'sqlite3'
group :assets do
gem 'sass-rails', '~> 3.2.3'
gem 'coffee-rails', '~> 3.2.1'
gem 'uglifier', '>= 1.0.3'
end
gem 'jquery-rails'
gem 'jquery-rails'
gem "select2-rails"
application.js is :
//= require jquery
//= require jquery_ujs
//= require select2
//= require_tree .
application.css is :
*= require_self
*= require_tree .
*= require select2
What I am missing here ?
I met the same problem. Problem solved by restarting the server.

Rails 3 - Require - Path Not Found

I have:
Windows XP Professional SP3
Ruby 1.8.7
Rails 3.0.10
Bundler 1.0.15
ImageMagick 6.5.6 Q8
Rmagick 2.12.9
My gemfile:
gem 'rmagick-2.12.0-x86-mswin32', '2.12.0', :path => 'c:/sites/uplodify/vendor'
My controller:
require 'RMagick'
Here I have installed my rmagick gem:
c:/ruby/ruby187/lib/ruby/gems/1.8/gems/rmagick-2.12.0-x86-mswin32/
But when I launch the controller, there is a message:
no such file to load -- RMagick
Then, I change require 'RMagick' to require 'c:/ruby/ruby187/lib/ruby/gems/1.8/gems/rmagick-2.12.0-x86-mswin32/lib/RMagick.rb', and it's working!!!
Question:
why require 'RMagick' is not working, but require 'c:/ruby/ruby187/lib/ruby/gems/1.8/gems/rmagick-2.12.0-x86-mswin32/lib/RMagick.rb' is working????
Thanks a lot!
ADDED: Hi, people. I glad to say how I solved the problem. My way was following recomendations on http://www.waydotnet.com/blog/2010/02/rmagick-on-ruby-1-9-1-i386-mingw32-work-d/....step by step...
In your Gemfile:
gem 'rmagick', '2.12.0', :require => 'RMagick'
and remove the require in your controller.
You're not really supposed to require your dependencies in your rails app, bundler should do it automatically. The :require option tells bundler that it should do a require 'RMagick' so you don't have to do it manually.

asset pipeline not generating application.js application.css

not sure what I'm doing wrong. but I get:
GET http://localhost:3001/assets/application.css 404 (Not Found)
Here is my config:
gem 'rails', '3.1.0.rc3'
gem 'rake', '0.9.2'
group :assets do
gem 'sass'
gem 'coffee-script'
gem 'uglifier'
gem 'sprockets'
end
in application.rb:
config.assets.enabled = true
in app/assets/javascripts/application.js:
//= require jquery
//= require jquery_ujs
//= require_tree .
similarly for app/assets/stylesheets/application.css
Why aren't the /assets/application.[css|js] generated/accessible? do I need to run something manually? also is sprockets needed or it's part of rails now?
It's not a specific answer to your problem, but it might solve it: I ran into a lot of issues which were fixed by switching to rc5 - I notice in your gemfile you're using rc3. I was getting a lot of hiccups like this when I was on rc4.
You don't need to add sprockets in your gemfile anymore once you do this either. Also, you don't mention it but do you have gem 'jquery-rails' in your gemfile too?
As Richard pointed out, moving to rc5 helped:
gem 'rails', '3.1.0.rc5'
but I was still getting "stack level too deep" issues which I finally figured out was due to my version of sprockets (beta.13) so I added a previous version the gem file:
gem 'sprockets', '2.0.0.beta.12'
and things are working fine :)
I was running into this problem as well and it took me a lot of tinkering to get it back to a working state. What I finally ended up doing that worked is:
Adding the following line to application.rb:
Bundler.require *Rails.groups(:assets) if defined?(Bundler)
Changing up my Gemfile so that I had the following defined:
group :assets do
gem 'sass-rails', "~> 3.1.0.rc"
gem 'coffee-rails', "~> 3.1.0.rc"
gem 'uglifier'
end
Bundle install, relaunch my server and voila, I have css and js again.

Rails 3 Cucumber Load Error

I am trying to get cucumber to work with Rails 3.
But whenever I try to run the cucumber features I get an load error.
cucumber-0.7.3/lib/cucumber/ast/feature_element.rb:2:in `require': no such file to load -- gherkin/parser/tag_expression (LoadError)
I have added the following gems to the Gemfile
gem "rspec", '>= 2.0.0.beta.19'
gem 'capybara'
gem 'database_cleaner'
gem 'cucumber-rails', '~> 0.1.1.rc6'
gem 'cucumber', '~> 0.7.0.beta.8'
gem 'rspec-rails', '~> 2.0.0.beta.19'
gem 'spork'
gem 'launchy'
I'm running on ruby-1.9.2-p0
Any suggestions?
I was getting the same error and was able to move past it by forcing gherkin to be loaded in Gemfile instead of as a cucumber dependency.
So, assigning specific version to Gherkin and >= to cucumbers:
...
gem 'gherkin', '2.1.5'
gem 'cucumber-rails', '>=0.3.2'
gem 'cucumber', '>=0.8.5'
...