Rack::Deflater works if only added to config.ru - ruby-on-rails-3

Why am I getting Error: incorrect header check when I add
class Application < Rails::Application
config.middleware.use Rack::Deflater
...
...but not when I add use Rack::Deflater to config.ru? I double checked: gzip works and compresses responses.
Rails 3.2.15
jRuby 1.7.13

It's a bug of jRuby 1.7
https://github.com/rack/rack/issues/571
And it was fixed in 1.7.23, so I just had to upgrade.

Related

rails 3 - LoadError (cannot load such file -- zip/zip)

I'm using rubyzip to zip a csv file so uses can download it. This works perfectly in development mode. But when I tried zipping the file on the production server (rackspace) I received the error: LoadError (cannot load such file -- zip/zip). Is it a path issue? Anyone know a fix?
The error is being called in my code on this line: require 'zip/zip'
I've tried the solution from here, but it didn't help.
I fixed this problem by specifying gem version 0.9.9 in Gemfile:
gem 'rubyzip', "~> 0.9.9"
Using rubyzip (1.0.0) caused an error.
When upgrading rubyzip to 1.0.0 change require 'zip/zip' to require 'zip'.
I had this problem after adding roo to a Rails project.
Roo needed the new interface, something else (some other gem) was using the old interface - so most of these answers didn't work (couldn't lower the version of rubyzip, rubyzip2 is deprecated, didn't have require zip/zip in my project).
What worked for me was cassio-s-cabral's answer referring to the rubyzip github page.
gem 'rubyzip', '>= 1.0.0' # will load new rubyzip version
gem 'zip-zip' # will load compatibility for old rubyzip API.
I had the same problem: error thrown on "require 'zip/zip'" code, and the solution from this post also did not help.
After a long research I found that the problem was that my "require 'zip/zip'" statement was done in a separate
lib/exporters/package_exporter.rb
file, and for some reason "require" statements are not handled in "lib" folder in production by default.
When I moved "require 'zip/zip'" to the beginning of my
app/controllers/packages_controller.rb
the problem was solved!
I had a similar issue with active_support, just added the 'zip' gem to my Gemfile and it worked fine
I'm use rubyzip2 gem to fix this problem
gem 'rubyzip2'
what work for me was to install 2 gems:
gem install rubyzip
gem install zip
and in the script put
require 'rubygems'
require 'zip/zip'
In their github page explains what to do.
Rubyzip interface changed!!! No need to do require "zip/zip" and Zip
prefix in class names removed.
If you have issues with any third-party gems what required old
version of rubyzip you can use next workaround:
gem 'rubyzip', '>= 1.0.0' # will load new rubyzip version
gem 'zip-zip' # will load compatibility for old rubyzip API.

Rails App doesn't work on production enviroment

I have a rails app set up with Nginx + Passenger. When i have rails_env development; on my nginx.conf everything works fine, but when I remove it so the app get server on production env it just doesnt work, seems like its not loading gems or something. Feel free to take a look at the errors here www.luisurraca.co.cc
error message:
undefined method `has_attached_file' for #<Class:0x00000003b0be10>
Exception class:
NoMethodError
Right now its referring to the paperclip gem, but if i start removing gems from the gemfile it will display error from some other gem and so on.
Any ideas what the issue might be?
You probably defined paperclip/whatever in development group and it is not installed with bundle install --deployment. To see installed gems do bundle show not gem list.
did you specify ruby path for nginx? it should look like this:
http {
passenger_root /home/rlisowski/.rvm/gems/ruby-1.9.3-p194/gems/passenger-3.0.13;
passenger_ruby /home/rlisowski/.rvm/wrappers/ruby-1.9.3-p194/ruby;
# ....

Rails 3 - Error after deploying to Heroku

I have an application working in localhost and also heroku. The last time that I pushed the new version to heroku I got an error during heroku db:migrate and did heroku db:push and everything was ok.
I get the following error when executing the App.
/app/.bundle/gems/ruby/1.9.1/gems/aws-s3-0.6.2/lib/aws/s3/extensions.rb:206:in `const_missing_from_s3_library': uninitialized constant AnswersController::Authentication (NameError)
Here is the relevant code
class AnswersController < ApplicationController
include Authentication
...
Authentication is a module defined in lib:
# encoding: utf-8
require 'base64'
require 'openssl'
module Authentication
...
It is working in localhost but not in heroku.
Any help??
Thanks
Try adding the lib folder to your the config.auto_load path in application.rb
config.autoload_paths += %W(#{config.root}/lib)
Also, take a look at this link.

Rails 3.1 / mysql2 error : "MySQL server has gone away"

I'm experiencing trouble upgrading my rails 2.3.14 / ruby 1.8.7 app to 3.1.1/1.9.2 : I have some
(ActiveRecord::StatementInvalid) "Mysql2::Error: MySQL server has gone away"
errors happening sporadically. It's important to precise that I never had such issues with the 'mysql' gem on 2.3.14 and the exactly same db (so the bug shouldn't come from mysql (v5.5.10)).
Example :
$ rails c production
Loading production environment (Rails 3.1.1)
ruby-1.9.2-p290 :001 > ActiveRecord::Base.connection.active?
=> false
ruby-1.9.2-p290 :002 > exit
$ rails c production
Loading production environment (Rails 3.1.1)
ruby-1.9.2-p290 :001 > ActiveRecord::Base.connection.active?
=> true
This happens only with my (remote) production database, no problem with my local development db. I've tried to set "reconnect: true" in my database.yml but it led to a
Mysql2::Error: Host '****' is blocked because of many connection errors; unblock with 'mysqladmin flush-hosts':...
I've tried to isolate the problem with a little rb script only loading mysql2 and activerecord but I didn't manage to reproduce the bug that way (so it may be linked to the rails stack).
I can't go back from the 'mysql2' to the 'mysql' gem because of encoding issues ( http://www.rorra.com.ar/2010/07/30/rails-3-mysql-and-utf-8/ ). As a consequence, I had to rollback my production to my rails 2.3.14 app, which saddens me very much...
Do you see what I can do to debug this ? I can't even find a sure way to reproduce the error... Have anyone met the same bug ?
I just found few people mentionning this bug (ex : https://github.com/brianmario/mysql2/issues/213) but not a solution.
Thanks for your help.
Ok, I think I solved my problem. I didn't notice it when I posted my question, but it seemed that the error was timeout related : after about 20s, activerecord losts its connection.
$ rails runner "sleep 23; puts ActiveRecord::Base.connection.active?"
=> true
$ rails runner "sleep 25; puts ActiveRecord::Base.connection.active?"
=> false
So I dug further and I realized that mysql and mysql2 gems didn't deal with the MySQL 'wait_timeout' param the same way : mysql gem doesn't set it thus uses the MySQL default value 28800, whereas mysql2 gem sets it at 2592000 if not defined in the database.yml.
But I have the impression that the value 2592000 is over the max value for this param : 2147483 ! Which could lead to the unexpected behavior I described...
I build a script test showing the bug : https://gist.github.com/1514154
And if I had some apparently random disconnect while loading rails console (cf my question), I think it's because of my app taking a long time to load and me sometimes waiting a few seconds before typing my command.
I can't explain why we are so few to encounter this problem. Perhaps it's specific to my conf (remote database, MySQL version ?). I've tried with another remote staging database : the bug didn't reproduce...
So as a conclusion, I will set wait_timeout: 2147483 in my database.yml. And maybe pull request rails...
Had a lot of lost connections - but I couldn't say if they went away due to the following tweak or elsewise :/
Had to throw the following script into initializers and add a line of configuration to each of my databases in my database.yml like this:
...
flags: <%= 65536 | 131072 %>
...
The script looks like this:
/config/initializers/mysql2.rb
module ActiveRecord
class Base
# Overriding ActiveRecord::Base.mysql2_connection
# method to allow passing options from database.yml
#
# Example of database.yml
#
# login: &login
# socket: /tmp/mysql.sock
# adapter: mysql2
# host: localhost
# encoding: utf8
# flags: 131072
#
# #param [Hash] config hash that you define in your
# database.yml
# #return [Mysql2Adapter] new MySQL adapter object
#
def self.mysql2_connection(config)
config[:username] = 'root' if config[:username].nil?
if Mysql2::Client.const_defined? :FOUND_ROWS
config[:flags] = config[:flags] ? config[:flags] | Mysql2::Client::FOUND_ROWS : Mysql2::Client::FOUND_ROWS
end
client = Mysql2::Client.new(config.symbolize_keys)
options = [config[:host], config[:username], config[:password], config[:database], config[:port], config[:socket], 0]
ConnectionAdapters::Mysql2Adapter.new(client, logger, options, config)
end
end
end

Changing the en.yaml for another one in rails

I managed to get a fr.yaml. I want this to be the default, an old Rails 2.2 tutorial says to add:
config.i18n.default_locale = :fr
in environment.rb
It does not work, my rails server crashes on this config line.
What is the syntax for this setting in Rails 3? I do not want a multi-language app, I want to use only the french settings.
In Rails3, you add this line to application.rb
config.i18n.default_locale = :fr
This goes in config/application.rb in rails 3.