Overriding rake task fails after upgrading to rails 4 - ruby-on-rails-4

I am trying to upgrade my app from rails 3.2.18 to rails 4.0 and I'm stuck on an issue with rake.
I have a custom doc.rake task that overrides doc:app with the following code inside that worked fine on rails 3:
# Replace Rails' rake doc:app with ours, which uses yardoc
Rake::Task["doc:app"].clear.enhance do
# Uses .yardopts_app file in rails root
app_dir = 'doc/generated/app'
sh "rm -rf #{app_dir}"
sh "bundle exec yardoc --plugin rails --yardopts .yardopts_app"
app_doc_files_dir = "#{app_dir}/doc-files"
Dir.mkdir( app_doc_files_dir )
cp_r( 'doc/files/app/doc-files/.', app_doc_files_dir )
end
Since upgrading rails, any rake task I try to run fails with the error:
rake aborted!
Don't know how to build task 'doc:app'
I'm really at a loss as to why this is happening. I can't find any reference to rails 4 removing the default doc:app task, so it should still exist for me to overwrite.

I was able to solve this by adding
require 'rails/tasks'
to the top of my rake file. So my full rake file looks like this now:
require 'rdoc/task'
require 'rails/tasks'
Rake::Task["doc:app"].clear
namespace :doc do
RDoc::Task.new('app') do |rdoc|
...
end
end

Related

Rails: Production assets:precompile error

I am trying to deploy my app on Heroku but I don't know why the bellow error occurs.
I have gem 'rails_12factor', group: :production so I don't use config.serve_static_assets = true and config.assets.initialize_on_precompile as in the documentation explained that they are not needed in Rails 4.
When I execute these two commands respectively:
bundle exec rake assets:precompile
RAILS_ENV=production bundle exec rake assets:precompile
I get this error.
DEPRECATION WARNING: The configuration option `config.serve_static_assets` has been renamed to `config.serve_static_files` to clarify its role (it merely enables serving everything in the `public` folder and is unrelated to the asset pipeline). The `serve_static_assets` alias will be removed in Rails 5.0. Please migrate your configuration files accordingly. (called from block in tsort_each at /usr/local/lib/ruby/2.2.0/tsort.rb:226)
I, [2016-06-14T13:21:21.336814 #10455] INFO -- : Writing /home/rails/Desktop/hammasir/public/assets/font-awesome.min-1c15db9e10c99a36820b80616445a837a002b3f3969047f3375fba65f8fef2ba.css
I, [2016-06-14T13:21:21.337563 #10455] INFO -- : Writing /home/rails/Desktop/hammasir/public/assets/font-awesome.min-1c15db9e10c99a36820b80616445a837a002b3f3969047f3375fba65f8fef2ba.css.gz
I, [2016-06-14T13:21:21.341449 #10455] INFO -- : Writing /home/rails/Desktop/hammasir/public/assets/bootstrap.min-139ad6ac9cbd7b8cd15fa3f80b9b69e3ead570cb9686b3bb42b73a19ed62dcef.css
I, [2016-06-14T13:21:21.343432 #10455] INFO -- : Writing /home/rails/Desktop/hammasir/public/assets/bootstrap.min-139ad6ac9cbd7b8cd15fa3f80b9b69e3ead570cb9686b3bb42b73a19ed62dcef.css.gz
I, [2016-06-14T13:21:21.400914 #10455] INFO -- : Writing /home/rails/Desktop/hammasir/public/assets/jquery.fancybox-9eb4dcf39f4ad63c3bff3f55e2a0e5e8a32578cc4553c94633ce0ccdc08c2bea.css
I, [2016-06-14T13:21:21.401335 #10455] INFO -- : Writing /home/rails/Desktop/hammasir/public/assets/jquery.fancybox-9eb4dcf39f4ad63c3bff3f55e2a0e5e8a32578cc4553c94633ce0ccdc08c2bea.css.gz
I, [2016-06-14T13:21:21.405283 #10455] INFO -- : Writing /home/rails/Desktop/hammasir/public/assets/animate-0af100ee0144b8c4dc6de8605097b0920d4ea4aad067cc34fbaa7ab525d4e6a8.css
I, [2016-06-14T13:21:21.405707 #10455] INFO -- : Writing /home/rails/Desktop/hammasir/public/assets/animate-0af100ee0144b8c4dc6de8605097b0920d4ea4aad067cc34fbaa7ab525d4e6a8.css.gz
rake aborted!
Sass::SyntaxError: Invalid CSS after "}": expected selector or at-rule, was "}"
(sass):86
Tasks: TOP => assets:precompile
(See full trace by running task with --trace)
I debugged and checked one of the files but I couldn't find any error like forgetting to use ), } or ; . Also, I cleaned the whole content of one of them and replace it by a simple CSS rule, but still I get the error!!
This error is also happening when I try to push my app to Heroku. Please, help me to understand what is the reason and its solution??
This is the answer I found, wishing it to be useful for others, too.
To solve the DEPRECATION WARNING, update your gems as expressed by:
Asset pipeline DEPRECATION WARNING tsort.rb:226
And about the main error, you should find which file causes the error exactly. The error output and mentioned files in it are misleading and not necessarily contain syntax error.
You can work with your assets.rb file to find which file (files) contains syntax error. Comment or remove all of the referred files in assets.rb except one, redo asset precompile command in your production mode:
RAILS_ENV=production bundle exec rake assets:precompile
and repeat it for all other css files to understand which one contains the error. This time the output of this command will be helpful and refer exactly to the problem. Then, it would be easy to find the error and fix it.

Rails 4 asset pipeline in production

My Rails app that I am upgrading to 4.2 from 3.2 has strange behavior in regards to the asset pipeline.
The guide says to use: RAILS_ENV=production bin/rake assets:precompile which causes this error:
Sass::SyntaxError: $red: "CC" is not a number for `rgba'
(sass):86
ArgumentError: $red: "CC" is not a number
The --trace doesn't point to any of my files and odder still is that I don't have any sass files to begin with.
I ran it without the RAILS_ENV and it compiled without complaint and everything seems to work.
My app has multiple layouts and themes which made for a slightly more complex and verbose set of asset manifests.
My question is, even though it seems to work is using that rake task without the RAILS_ENV=production going to cause issues?
It looks like you are actually sending an incorrect value to the sass compiler. Grep the code for $red or rgba and enter a correct list of numbers for the rgba statement that is causing the error.

Rails 4 server fails, Ruby 2.0 segmentation fault, Abort trap 6

I just started going through railstutorial.org and getting my development environment setup. When I got to the section 1.2.5 to run rails server for the fist_app, I type the command and the following printed out:
$ rails server
/Users/aaronpflower/.rvm/gems/ruby-2.0.0-p481#railstutorial_rails_4_0/gems/sqlite3- < 1.3.8/lib/sqlite3/sqlite3_native.bundle: [BUG] Segmentation fault ruby 2.0.0p481 (2014-05-08 revision 45883) [x86_64-darwin13.2.0]
Then followed by 500 lines of text
0 enumerator.so
1 /Users/aaronpflower/.rvm/rubies/ruby-2.0.0-p481/lib/ruby/2.0.0/x86_64-darwin13.2.0/enc/encdb.bundle
2 /Users/aaronpflower/.rvm/rubies/ruby-2.0.0-p481/lib/ruby/2.0.0/x86_64-darwin13.2.0/enc/trans/transdb.bundle
3 /Users/aaronpflower/.rvm/rubies/ruby-2.0.0-p481/lib/ruby/2.0.0/x86_64-darwin13.2.0/rbconfig.rb
4 /Users/aaronpflower/.rvm/rubies/ruby-2.0.0-p481/lib/ruby/site_ruby/2.0.0/rubygems/compatibility.rb
5 /Users/aaronpflower/.rvm/rubies/ruby-2.0.0-p481/lib/ruby/site_ruby/2.0.0/rubygems/defaults.rb
6 /Users/aaronpflower/.rvm/rubies/ruby-2.0.0-p481/lib/ruby/site_ruby/2.0.0/rubygems/deprecate.rb
7 /Users/aaronpflower/.rvm/rubies/ruby-2.0.0-p481/lib/ruby/site_ruby/2.0.0/rubygems/errors.rb
8 /Users/aaronpflower/.rvm/rubies/ruby-2.0.0-p481/lib/ruby/site_ruby/2.0.0/rubygems/version.rb
9 /Users/aaronpflower/.rvm/rubies/ruby-2.0.0-p481/lib/ruby/site_ruby/2.0.0/rubygems/requirement.rb
Which ended with:
[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
Abort trap: 6
When this first happened double checked the steps leading up to this in the tutorial, since being a beginner that was a high possibility. I typed the follow commands and everything checkout. (I'm also using OS 10.9.3)
$ rails -v
Rails 4.0.5
$ ruby -v
2.0.0p481
$ rvm -v
1.25.27
$ brew doctor
system ready to brew
Through searching some posts have suggested to uninstall sqlite3 and then re-install but I still got the same seg fault message. Not sure of the next step.
Your Rails -v and Ruby -v are correct for this tutorial.
I can also see from the input that your gemfile has gem 'sqlite3', '1.3.8' in it.
1: Have you bundled?
When was the last time you ran bundle update or bundle install?
How did you go about uninstalling sqlite3? Did you use $ gem uninstall sqlite3?
Try uninstalling and then reinstalling the gem.
2: - What version manager?
Did you use rvm, rbenv or homebrew to install? Using different version managers for different pieces can create communication issues.
3: Did you install Xcode?
This is taken from http://www.railstutorial.org:
"As a prerequisite, OS X users may need to install the Xcode developer tools. To avoid the (huge) full installation, I recommend the much smaller Command Line Tools for Xcode.
To install Xcode (my recommendation), look it up in the AppStore.
To install Command Line Tools (MHartl's recommendation) - https://developer.apple.com/downloads/
4: Are you using `bundle exec`?
Try bundle exec rails c and bundle exec rails s
5: Try 'refreshing' your bundle directory
If bundle exec doesn't work
Remove the .bundle/ directory and re-bundle with
rm -rf .bundle/ && bundle
I experienced the same issue, I just switched to a different ruby version
e.g;
rvm use 1.9.3-p484
and then bundle again.

Puppet install gem fails but gem is installed anyways

I have a Puppet manifest that installs the Zurb Foundation gem:
class compass {
package { ["rubygems"]:
ensure => 'installed'
}
package { ['zurb-foundation']:
ensure => '3.0.6',
provider => 'gem',
require => Package['rubygems']
}
}
This causes the following error when running puppet apply:
err: /Stage[main]/Compass/Package[zurb-foundation]/ensure: change from absent to 3.0.6 failed: Could not update: Execution of '/usr/bin/gem install -v 3.0.6 --include-dependencies --no-rdoc --no-ri zurb-foundation' returned 1: INFO: `gem install -y` is now default and will be removed
INFO: use --ignore-dependencies to install only the gems you list
Building native extensions. This could take a while...
ERROR: Error installing zurb-foundation:
ERROR: Failed to build gem native extension.
/usr/bin/ruby1.9.1 extconf.rb
/usr/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require': cannot load such file -- mkmf (LoadError)
from /usr/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from extconf.rb:4:in `<main>'
Gem files will remain installed in /var/lib/gems/1.9.1/gems/ffi-1.9.0 for inspection.
Results logged to /var/lib/gems/1.9.1/gems/ffi-1.9.0/ext/ffi_c/gem_make.out
at /etc/puppet/manifests/classes/compass.pp:25
However, doing a gem list yields the following results:
# gem list
*** LOCAL GEMS ***
chunky_png (1.2.8)
compass (0.12.2)
fssm (0.2.10)
rake (10.1.0)
rb-fsevent (0.9.3)
sass (3.2.0.alpha.277)
zurb-foundation (3.0.6)
The error causes puppet apply to not complete properly, since a lot of items are skipped because of failed dependencies. What can I do?
I think that the problem is that you don't have the ruby dev kit installed for you ruby (that's what's used to build native extensions).
You'll want to add something like (it may be different depending on your version of ruby):
package { 'ruby-dev':
ensure => installed,
before => Package['zurb-foundation'],
}
This should allow the gem to be built properly and let your puppet run finish too.

Handlebars Asset not Compiling with ember-rails after Upgrade to Rails 4

I have a Rails app with Ember on the front-end. Today, I upgraded to Rails 4 and the only issue I cannot resolve is that my Handlebars templates are not being compiled or included as an asset (in development mode). I'm not getting any error messages.
I generated a brand new Rails 4 test app and installed Ember and it serves the Handlebars files just fine. All gems in the test app are present in my app. I tried running rake rails:upgrade, and that had no effect. I tried modifying the ember-rails source to output log messages and the messages and execution paths were the same for the test app and my app.
I'm requiring the templates the same way I always did:
require_tree ./templates
I tried using ember-rails 0.11.1 and from Github master, with no luck.
Related gem versions:
* ember-data-source (0.0.5)
* ember-rails (0.11.1 4dc902b)
* ember-source (1.0.0.rc2.0)
* sprockets (2.9.0)
* sprockets-rails (2.0.0.rc3)
* barber (0.4.1)
Templates are all in app/assets/javascripts/templates and all use the extension .handlebars. Although I tried .hbs and .js.hjs too.
From the Chrome console:
Ember.TEMPLATES
Object {}
I am able to manually compile assets from the Rails command line like this:
environment = Sprockets::Environment.new
environment.append_path 'app/assets/javascripts'
a = environment['templates/test.handlebars']
a.to_s => "..compiled template.."
And the engine is registered:
environment.engines
=> {..".handlebars"=>Ember::Handlebars::Template..}
Rails.application.config.assets.paths includes the app/assets/javascripts folder, as it should.
Any help with this would be greatly appreciated, Thanks!
I've narrowed it down to the following block in ember-rail's engine.rb file. For my app, it is sending register_engine on Sprockets, not app.assets. On the fresh Rails 4 test app, it was also doing this. However, in my app when I force the execution to use app.assets, the handlebar templates are compiled.
I believe since my app was upgraded from Rails 3, somewhere some configuration is missing to properly use Sprockets. I'll post more when I know.
initializer "ember_rails.setup", :after => :append_assets_path, :group => :all do |app|
sprockets = if ::Rails::VERSION::MAJOR == 4
Sprockets.respond_to?('register_engine') ? Sprockets : app.assets
else
app.assets
end
sprockets.register_engine '.handlebars', Ember::Handlebars::Template
sprockets.register_engine '.hbs', Ember::Handlebars::Template
sprockets.register_engine '.hjs', Ember::Handlebars::Template
end
UPDATE:
For me,changing the railties order in application.rb was enough to fix the problem. I believe some other engine was clearing the Sprockets config, so by loading the Ember::Rails engine later in the process, I was able to hack a way around that issue.
config.railties_order = [:main_app, :all, Ember::Rails::Engine]