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.
Related
I started using the best_in_place gem. It worked fine in my local development machine, but when I deployed the code to the production server, I get:
ActionView::Template::Error (undefined method `best_in_place' for #<#<Class:0xc088ef8>:0xba694a0>):
76: <% t.each do |ticket| %>
77: <tr>
78: <td><%= check_box_tag "tickets[ids][]", ticket.id, false, :class => "status_change" %></td>
79: <td><%= best_in_place ticket, :position, {:inner_class => "input-mini", :type => :input} %></td>
80: <td><%= ticket.id %></td>
81: <td><%= ticket.job_number %></td>
82: <td><%= link_to ticket.name, edit_ticket_path(ticket) %></td>
app/views/tickets/index.html.erb:79:in `block (3 levels) in _app_views_tickets_index_html_erb___947812068_98658810'
app/views/tickets/index.html.erb:76:in `block (2 levels) in _app_views_tickets_index_html_erb___947812068_98658810'
app/views/tickets/index.html.erb:56:in `each'
app/views/tickets/index.html.erb:56:in `block in _app_views_tickets_index_html_erb___947812068_98658810'
app/views/tickets/index.html.erb:50:in `_app_views_tickets_index_html_erb___947812068_98658810'
app/controllers/tickets_controller.rb:11:in `index'
It's as if the gem is not installed. I did make sure I did a bundle install.
View:
<td><%= best_in_place ticket, :position, {:inner_class => "input-mini", :type => :input} %></td>
Gemfile:
source 'https://rubygems.org'
gem 'rails', '3.2.11'
# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'
group :development do
gem 'sqlite3'
end
# 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'
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
# gem 'therubyracer', :platforms => :ruby
gem 'uglifier', '>= 1.0.3'
end
gem 'jquery-rails'
group :production do
gem "mysql", "~>2.8.1"
end
# 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 'devise'
gem 'best_in_place'
gem 'paper_trail'
gem 'ckeditor_rails'
gem 'bootstrap-sass'
gem 'bootstrap-datepicker-rails'
gem 'carrierwave'
gem 'ransack'
gem 'nested_form'
gem 'will_paginate'
gem 'capistrano'
gem 'therubyracer'
I ended up having to reboot the server and restart passenger standalone. After this, best_in_place worked. I'm not sure why this is the case, but if anyone is willing to expand on what might have been happening, I will change the correct answer to their solution.
How do I go about tracking down an error when all production.log gives me is this?
11: <%= javascript_include_tag "application" %>
12: <%= csrf_meta_tags %>
13: <%= yield(:head) %>
app/views/layouts/application.html.erb:10:in `_app_views_layouts_application_html_erb__4417234491726047977_45250520'
app/controllers/docs_controller.rb:27:in `index'
Processing by ErrorsController#broken as HTML
Rendered errors/broken.html.erb within layouts/application (0.5ms)
Completed 500 Internal Server Error in 16ms
FYI: the line 10 of application.html.erb is <%= stylesheet_link_tag "application", :media => "all" %> so I'm assuming it has something to do with either my CSS or my gemfile. How do I investigate it further?
Also, my gemfile:
source 'https://rubygems.org'
gem 'rails', '3.2.12'
gem 'json', '1.7.7'
gem 'mysql2'
group :assets do
gem 'coffee-rails'
end
group :development do
gem 'better_errors'
gem 'binding_of_caller'
gem 'meta_request'
end
group :development, :test do
gem 'rspec-rails'
gem 'steak'
gem 'factory_girl_rails'
end
gem 'sass'
gem 'less-rails'
gem 'less-rails-bootstrap'
gem 'jquery-rails'
gem 'devise', '>= 2.1.2'
gem 'cancan'
gem 'paperclip', '~> 3.0'
gem 'therubyracer'
gem 'yaml_db'
gem 'passenger'
gem 'capistrano'
gem 'prawn'
gem 'bootstrap-wysihtml5-rails'
gem 'turbolinks'
gem 'jquery-turbolinks'
gem 'kaminari'
gem 'truncate_html'
gem 'rails3-jquery-autocomplete'
gem 'whenever'
gem 'impressionist'
gem 'acts_as_list'
gem 'acts_as_indexed'
gem 'state_machine'
gem 'exception_notification'
gem 'public_activity'
My gemfile needed uglifier, which was imported with an old version of another gem.
gem 'uglifier'
fixed it.
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.
Ive been following this introductory to Rails testing and Ive run into an issue I cant seem to find the solution to. Im very familiar with Rails but this is my first foray into testing.
Anyhow, I have a very basic model test, not even fully implemented and when I try and run rspec spec/models/admin_spec.rb. I get the following error in the Admin has a valid factory line (full code below)
Admin has a valid factory
Failure/Error: Factory.create(:admin).should be_valid
NameError:
uninitialized constant Factory
# ./spec/models/admin_spec.rb:6:in `block (2 levels) in <top (required)>'
I assume FactoryGirl isnt being loaded for some reason but I was under the impression it should be automatically loaded. Below is the full code from my Gemfile, /spec/models/admin_spec.rb and /spec/factories/admins.rb
Thanks very much for your help
Gemfile
source 'https://rubygems.org'
gem 'rails', '3.2.2'
gem 'mysql2'
gem 'jquery-rails'
gem 'haml'
gem 'bcrypt-ruby', :require => 'bcrypt'
gem 'bootstrap-sass', '~> 2.0.2'
gem 'capistrano'
gem 'json'
gem "paperclip", '~>3.0'
gem 'airbrake'
gem 'acts_as_list'
gem 'nested_form', :git => 'https://github.com/ryanb/nested_form.git'
gem 'bootstrap-wysihtml5-rails'
gem 'will_paginate', '~> 3.0'
gem 'bootstrap-will_paginate'
gem 'thinking-sphinx', '2.0.10'
gem 'sass-rails', '~> 3.1'
gem 'coffee-rails'
gem 'uglifier'
# gem 'compass'
group :development do
gem 'awesome_print'
gem 'wirble'
end
group :development, :test do
gem 'rspec-rails'
gem 'factory_girl_rails'
end
group :production do
gem 'execjs'
gem 'therubyracer'
end
group :test do
# Pretty printed test output
gem 'turn', :require => false
gem 'faker'
gem 'capybara'
gem 'guard-rspec'
gem 'launchy'
end
/spec/factories/admin.rb
require 'faker'
FactoryGirl.define do
factory :admin do |f|
f.name Faker::Name.name
f.email Faker::Internet.email
end
end
/spec/models/admin_spec.rb
require 'spec_helper'
describe Admin do
it "has a valid factory" do
Factory.create(:admin).should be_valid
end
it "is invalid without a name"
it "is invalid without an email"
end
It should be FactoryGirl.create instead. Apparently Factory was deprecated and now has been removed, look at the comments in the link you provided :)
In fact in your spec_helper.rb under Rspec.configure do...end you can add
RSpec.configure do |config|
config.include FactoryGirl::Syntax::Methods
end
This will save you the trouble of the prefixing FactoryGirl. before :build and :create altogether:
require 'spec_helper'
describe Admin do
it "has a valid factory" do
create(:admin).should be_valid
end
it "is invalid without a name"
it "is invalid without an email"
end
Refer: FactoryGirl Documentation
This isn't an answer to your question, but I noticed there is an obscure error in your use of Faker with FactoryGirl. f.name and f.email will be the same for every FactoryGirl.create or FactoryGirl.build.
f.name Faker::Name.name
f.email Faker::Internet.email
Add curly braces around the Faker calls so that each reference to a Factory will generate random Faker data.
f.name { Faker::Name.name }
f.email { Faker::Internet.email }
Also, be sure that you are including the require statement in your spec_helper.rb file.
require 'factory_girl_rails'
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.