Glenn JahnkeGlenn Jahnke
Standup 8/11/2011: Whole lotta Rails
edit Posted by Glenn Jahnke on Thursday August 11, 2011 at 09:39AM

Ask for Help

"What do you tell Rails the default timezone is if your database has no concept like that?"

The best solution was to convert all rows in your DB to UTC and set Rails to also use UTC. There are MySQL commands to convert whole databases over to UTC, and can be run overnight if necessary.

Interesting Things

There is a new release of Fixture Builder!

  • Supports Rails 2 and 3
  • Supports using existing Rails style fixture files using config.legacy_fixture = Dir[path_to_old_fixtures] in your fixture_builder.rb file
  • Its better tested too!
  • Go grab it at https://github.com/rdy/fixture_builder#readme

Rails 3 Helpers

Rails now includes all helpers across your project in controllers that extends ApplicationController. Apparently there isn't a setting to override this behavior either, and this is a change from Rails 2 where the scaffold would just include a line at the top of your controller like helpers :all which could easily be deleted.

Jason NobleJason Noble
Installing Rails development stack on OS X Lion
edit Posted by Jason Noble on Thursday August 04, 2011 at 09:15PM

I recently started working with OS X Lion at home and started researching the best way to get a Ruby on Rails environment up and running quickly.

After a little searching, I found a really well written article by Frederico Araujo over at http://www.frederico-araujo.com/2011/07/30/installing-rails-on-os-x-lion-with-homebrew-rvm-and-mysql/.

Fred's blog post walks you through step by step getting Homebrew, RVM, Ruby 1.9.2 and MySQL up and running.

It worked perfectly.

Thanks Fred!

Kelly FelkinsKelly Felkins
SF Standup for Monday, 4/25/2011: What gem do you use for file upload?
edit Posted by Kelly Felkins on Tuesday April 26, 2011 at 07:17AM

Help

What are projects using for file upload? Paperclip? Carrierwave?

Most continue to use Paperclip, though a few projects have successfully used Carrierwave. Carrierwave apparently has better mongo support.

I tried to setup ruby and rails, and installed the latest mysql gem and I get warning messages about the mysql gem.

Others have experienced this too and offered to help. The main answer seemed to be "the warnings are lies, it will work."

Interesting

  • Checkout Pry. It's an irb replacement that includes tab completion and cd and ls for navigating scopes.

John PignataJohn Pignata
Converting Rails application data from MySQL to PostgreSQL
edit Posted by John Pignata on Monday November 23, 2009 at 06:07PM

One of our projects had a pending chore in Tracker to move its backend to PostgreSQL from MySQL. This project has about a quarter of a million rows of production data and around a hundred tables in its schema which needed to be exactly migrated into PostgreSQL.

Forklifting the data proved more complicated than expected due to incompatibilities in the two DBMS' syntax such as in the way string escaping worked, how booleans were represented and a bunch of other small but painful differences. Despite MySQL's mysqldump utility including a command-line option to write statements in PostgeSQL format, it became clear that it wasn't going to be simple to create a repeatable procedure to do this work across our environments.

There's a bunch of information out there about how to approach this problem but none felt right. Most are multi-step manual procedures that require altering a dump file using sed or perl and others require the data to be loaded into an intermediary database and massaged prior to import. After testing some of these approaches, Todd and I decided to timebox ourselves to an hour to test the viability of a Ruby script using the DBI gem to move the data. We came up with:

require 'dbi'
require 'dbd/mysql'
require 'dbd/pg'

begin
  mysql = DBI.connect("DBI:Mysql:source:localhost", "username", "password")
  postgres = DBI.connect("DBI:Pg:destination:localhost", "username", "password")

  mysql.select_all("SHOW TABLES") do |table|
    next if ['schema_migrations', 'sessions'].include?(table.to_s)
    select = mysql.execute("SELECT * FROM #{table}")
    columns = select.column_names.map { |key| "\"#{key}\"" }.join(', ')
    placeholders = (['?'] * select.column_names.size).join(', ')
    insert = postgres.prepare("INSERT INTO #{table} (#{columns}) VALUES(#{placeholders})")
    select.each { |row| insert.execute(*row) }
    insert.finish
  end
rescue DBI::DatabaseError => e
  puts "Error #{e.err}: #{e.errstr}"
ensure
  mysql.disconnect if mysql
  postgres.disconnect if postgres
end

Our antiquely Perl-like script worked better than we expected — our application started right up with all of its data intact.

Has anybody out there encountered this need before? What kinds of solutions did you come up with?

Joe MooreJoe Moore
Standup 06/23/2009: Multi-table Inheritance?
edit Posted by Joe Moore on Tuesday June 23, 2009 at 04:29PM

Ask for Help

"Has anyone implemented mutli-table (class table) inheritance in Rails, as apposed to single table inheritance (STI)?"

  • There are some plugins that nobody has tried, such as inherits_from
  • What about a view to represent the super set of tables and rows?

"We're looking for a dead-simple, drop-in JS rating or 'starting' plugin."

Check out the start-rating jQuery plugin. Any other suggestions?

Brandon KeeneBrandon Keene
Standup 11/11/2008: Firefoxen goodness
edit Posted by Brandon Keene on Thursday November 13, 2008 at 01:20AM

Interesting Things

  • In response to our ask for help, Ray Baxter answered us in code with a script called Firefoxen. "It’s a script to automatically configure multiple installations of Firefox so that they open with different profiles." You can grab Firefoxen on GitHub. Thanks Ray!
  • IE7 sends odd Accept headers (*.* instead of an explicit text/html) which can cause undesired behavior in Rails. Someone suggested manually setting the format in a before_filter:

    params[:format] ||= 'text/html'
    This was discouraged because it can cause problems elsewhere. A better solution was to put the html format at the top of any `respond_to` blocks:
    def show
      respond_to.html # run by default when type cannot be determined
      respond_to.js
    end
    
  • The Ruby MySQL Gem version 2.7 leaks memory for very large queries. The solution is to remove the 2.7 gem and manually install version 2.8 from source. This library is no longer a gem and must be installed from the mysql-ruby-2.8 tarball.

Ask for Help

"As a followup to Firefox SSL certificate problems..."

It turns out that our server running nginx had an old version of OpenSSL installed. Upgrading OpenSSL solved the problem.

Kelly FelkinsKelly Felkins
Standup 7/24/2008
edit Posted by Kelly Felkins on Thursday July 24, 2008 at 04:45PM

Interesting

mysqldump and load

  • There was war story told involving software that's not generally available. However, one tidbit that may be of general interest is a reminder that you don't necessarily get a perfect copy of your mysql database when restoring from a dump of that database. Mysqldump by default writes the data of each table preceded by a DROP TABLE IF EXISTS and a CREATE TABLE statement. This covers you in most situations, but misses when new tables have been created since the dump was made -- those new tables are not deleted. They may not cause problems, but some systems are sensitive to the existence of those tables, such as rails and the schema_info and schema_migrations tables.

Ask for Help

  • question: Is merb hosting different from rails hosting?
    • answer: no