Rails - how to debug CSS? - html

My app works fine in development mode, I fail to push in to production however.
This is what I get from RAILS_ENV=production bundle exec rake assets:precompile --trace
** Invoke assets:precompile (first_time)
** Invoke assets:environment (first_time)
** Execute assets:environment
** Invoke environment (first_time)
** Execute environment
** Execute assets:precompile
rake aborted!
Sass::SyntaxError: Invalid CSS after "}": expected selector or at-rule, was "}"
(sass):1315
/Users/mohnstrudel/.rvm/gems/ruby-2.3.1/gems/sass-3.4.22/lib/sass/scss/parser.rb:1189:in `expected'
/Users/mohnstrudel/.rvm/gems/ruby-2.3.1/gems/sass-3.4.22/lib/sass/scss/parser.rb:1125:in `expected'
/Users/mohnstrudel/.rvm/gems/ruby-2.3.1/gems/sass-3.4.22/lib/sass/scss/parser.rb:42:in `parse'
/Users/mohnstrudel/.rvm/gems/ruby-2.3.1/gems/sass-3.4.22/lib/sass/engine.rb:406:in `_to_tree'
...
buch of lines
By using trial and error I narrowed the suspect down to bootstrap.min.css (it came bundled from template creator, using a plain bootstrap.min.css breaks the design).
Line 1315 and the code around looks like this:
.text-primary {
color: #337ab7
}
a.text-primary:focus,
a.text-primary:hover {
color: #286090 <-- this is exactly line 1315
}
.text-success {
color: #3c763d
}
a.text-success:focus,
a.text-success:hover {
color: #2b542c
}
This error is driving me mad, I can't even figure out what is wrong.
Is there a way to retrieve more informative error message?

Related

Custom rake task for DB: Table not found

I have a custom rake task, that creates a development DB with data for various situation. The core looks like this:
namespace :db do
task setup_seed: :environment do
Rake::Task['db:drop'].invoke
Rake::Task['db:create'].invoke
Rake::Task['db:schema:load'].invoke
Rake::Task['db:migrate'].invoke
Rake::Task['db:test:prepare'].invoke
Rake::Task['db:seed'].invoke
end
end
Everything runs fine, until db:seed is invoked, because it throws an error that tables does not exist. This is my seed.rb:
puts Rails.env
# => development
puts Article.count
# rake aborted!
# Mysql2::Error: Table 'app_test.articles' doesn't exist: SHOW FULL FIELDS FROM `articles`
# /usr/src/app/db/seeds.rb:2:in `<top (required)>'
# /usr/src/app/Rakefile:16:in `block (2 levels) in <top (required)>'
# Tasks: TOP => db:seed
I noticed two strange things here:
First of all it doesn't find the table articles (or any table). When I halt at the beginning of my seed file and look into the DB (development), the tables are present, but the test db is empty
I've printed the Rails.env and it returns development. However the failure message states that it tries to load the DB app_test.articles and not app_development.articles.
So I think this two issues are related.
It looks like you are running your rake task in development environment, but db:test:prepare runs in test by default. Try invoking:
RAILS_ENV=test rake db:setup_seed
I found the solution myself. The problem was, that the task Rake::Task['db:test:prepare'].invoke changes the environment to test, so putting that line to the bottom of the script and everything works:
namespace :db do
task setup_seed: :environment do
Rake::Task['db:drop'].invoke
Rake::Task['db:create'].invoke
Rake::Task['db:schema:load'].invoke
Rake::Task['db:migrate'].invoke
Rake::Task['db:seed'].invoke
Rake::Task['db:test:prepare'].invoke # this one should be at the bottom
end
end

can't run migration

I run
rake db:create
and getting strange error
rake aborted!
126: ═х эрщфхэ єърчрээ√щ ьюфєы№. - C:/Ruby192/lib/ruby/gems/1.9.1/gems/mysql2-
0.3.11-x86-mingw32/lib/mysql2/1.9/mysql2.so
I tried to reinstall bundler.
Is it gem problem ?
To solve this problem, reference to the following link:
http://maxivak.com/installing-mysql2-gem-on-ruby-1-9-2-and-rails-3-0-5-on-windows/
You need to include mysql-connector through the Rails DevKit.

Unit tests cannot find tables

I'm running unit tests on Rails 2.3 and I keep getting errors along these lines when I run rake test:units:
10) Error:
test_the_truth(BrokerTest):
ActiveRecord::StatementInvalid: Mysql::Error: Table 'shadow_test.users' doesn't exist: DELETE FROM `users`
/Library/Ruby/Gems/1.8/gems/after_commit-1.0.10/lib/after_commit/connection_adapters.rb:14:in `transaction'
I ran rake db:test:load prior to this, and it created the tables. However, when I check mysql after running the unit tests command, the tables are indeed missing. Something in the process of preparing for the unit tests causes the tables to go missing. Here's the debug log from running the test:
WARNING: 'task :t, arg, :needs => [deps]' is deprecated. Please use 'task :t, [args] => [deps]' instead.
at /Users/me/sources/shadow/lib/tasks/turk.rake:53
** Invoke test:units (first_time)
** Invoke db:test:prepare (first_time)
** Invoke db:abort_if_pending_migrations (first_time)
** Invoke environment (first_time)
** Execute environment
** Execute db:abort_if_pending_migrations
** Execute db:test:prepare
** Invoke db:test:load (first_time)
** Invoke db:test:purge (first_time)
** Invoke environment
** Execute db:test:purge
** Execute db:test:load
** Invoke db:schema:load (first_time)
** Invoke environment
** Execute db:schema:load
** Execute test:units
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby -I"lib:test" -I"/Library/Ruby/Gems/1.8/gems/rake-0.9.2.2/lib" "/Library/Ruby/Gems/1.8/gems/rake-0.9.2.2/lib/rake/rake_test_loader.rb" "test/unit/**/*_test.rb"
/Library/Ruby/Gems/1.8/gems/bundler-1.1.3/lib/bundler/runtime.rb:211: warning: Insecure world writable dir /usr/local/git/bin in PATH, mode 040777
NOTE: Gem.source_index is deprecated, use Specification. It will be removed on or after 2011-11-01.
Gem.source_index called from /Library/Ruby/Gems/1.8/gems/rails-2.3.14/lib/rails/gem_dependency.rb:21.
WARNING: using the built-in Timeout class which is known to have issues when used for opening connections. Install the SystemTimer gem if you want to make sure the Redis client will not hang.
/Users/me/sources/shadow/test/unit/../test_helper.rb:36: warning: already initialized constant BEANSTALK
Loaded suite /Library/Ruby/Gems/1.8/gems/rake-0.9.2.2/lib/rake/rake_test_loader
Started
EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE
Finished in 3.389328 seconds.
Some more background: I'm using Octopus for sharding and that may be somehow interfering with things??
Using the Octopus database sharding gem has a few issues on test case preparation. See GitHub issue: https://github.com/tchandy/octopus/issues/31.
You have a few options, the easiest of which is to disable Octopus for your development environment. Remove "- development" from your shards.yml file.
Otherwise, you can patch the issue by adding task:
task :reconnect_octopus do
if ActiveRecord::Base.connection.is_a?(Octopus::Proxy)
ActiveRecord::Base.connection.initialize_shards(Octopus.config)
end
end
task :'db:test:clone_structure' => :reconnect_octopus
or for Rails 3:
task :reconnect_octopus do
if ActiveRecord::Base.connection.is_a?(Octopus::Proxy)
ActiveRecord::Base.connection.initialize_shards(Octopus.config)
end
end
task :'db:structure:load' => :reconnect_octopus
This should stem off your issue listed above. Happy coding!

rake db:create failing on Win7 x64

Updated to include trace info
I'm setting up a Win7 machine for Ruby on Rails development and seem to have run into an issue with my rake tasks. When I call rake db: create the cmd window sits for a very long time and dumps the following:
C:\my\directory\rails>rake db:create --trace
(in C:/my/directory/rails)
** Invoke db:create (first_time)
** Invoke db:load_config (first_time)
** Invoke rails_env (first_time)
** Execute rails_env
** Execute db:load_config
** Execute db:create
foo already exists
foo already exists
C:/Ruby192/bin/rake: [BUG] Segmentation fault
ruby 1.9.2p136 (2010-12-25) [i386-mingw32]
-- control frame ----------
c:0001 p:0000 s:0002 b:0002 l:000b24 d:000b24 TOP
---------------------------
[NOTE]
You may have encountered a bug in the Ruby interpreter or extension libraries.
Bug reports are welcome.
For details: http://www.ruby-lang.org/bugreport.html
This application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information.
What does this mean? I am running Win7 Pro x64, MySQL 5.5, and Rails 3.
Apparently it was the dll that was faulty. Used this approach.

db:seed not loading models

I'm trying to seed my database with the standard db/seeds.rb method. This works fine on my development machine, but on my server, I get:
$ sudo rake db:seed RAILS_ENV=production --trace
** Invoke db:seed (first_time)
** Invoke environment (first_time)
** Execute environment
** Execute db:seed
rake aborted!
uninitialized constant Permission
/usr/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2503:in `const_missing'
/usr/local/lib/ruby/gems/1.8/gems/activesupport-2.3.4/lib/active_support/dependencies.rb:92:in `const_missing'
/path/.../.../.../.../db/seeds.rb:4
/usr/local/lib/ruby/gems/1.8/gems/rails-2.3.4/lib/tasks/databases.rake:215:in `load'
/usr/local/lib/ruby/gems/1.8/gems/rails-2.3.4/lib/tasks/databases.rake:215
/usr/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:636:in `call'
...
But when I check in the console, the model does exist:
$ script/console production
Loading production environment (Rails 2.3.4)
>> Permission
=> Permission(id: integer, ..., created_at: datetime, updated_at: datetime)
What am I forgetting?
In a comment to the blog posted linked to above and here again: http://www.builtfromsource.com/2011/02/09/getting-rake-dbseed-and-config-threadsafe-to-play-nice/
Bruce Adams mentions that one can call:
config.threadsafe! unless $rails_rake_task
to only turn on threadsafe when not running a rake task.
But as the issue is really that threadsafe turns off dependency_loading, you can simply add this line after config.threadsafe! to leave it enabled, but still load your environment as you expect.
config.dependency_loading = true if $rails_rake_task
It can be fixed by disabling threadsafe! in the environment configuration.
I just ran across a good approach to this problem in this article. I'll summarize here so people can (hopefully) find it quicker.
The idea is to turn off threadsafe in the production environment, first by editing config/environments/production.rb:
config.threadsafe! unless ENV['THREADSAFE'] == 'off'
You then set THREADSAFE=off when running rake tasks.