Etikettarkiv: rails

How to use git plugins in your subversion rails project

If you like me still use subversion for your own rails projects but you want to use all the latest and coolest rails plugins that are hosted in a git repository you need to do as follows.

Start with installing git. If you use OS X you can download an installer here.

After you’ve done that use the following line to clone the remote git repository in your local vendor/plugins directory.

git clone --depth 1 git://github.com/fauna/has_many_polymorphs.git vendor/plugins/has_many_polymorphs

Change the address to the git repository and the name of the directory under vendor/plugins to fit your needs. In the above example I got the has_many_polymorphs plugin from github.

The checked out directory can then be added to your subversion repository like all other files. If you later want to update the plugin all you have to do is enter the directory and execute.

git pull

This ‘Using Git like svn:externals’ article helped me figure this out.

How to copy production database data to the development database with Capistrano

At times it is useful to easily be able to copy the content of the production database to the database running on your local development machine. In my case I use mysql on the production server and sqlite on my MacBook Pro. Unfortunately the use of different database servers makes this task a bit more tricky.

With a bit of googling I found a bit of code here and there which I combined and modified and turned into the following snippet of code to be dropped into your Capistrano deploy.rb file.

desc "Copy production database to development database" task :update_dev_db, :roles => :db do db = YAML::load(ERB.new(IO.read(File.join(File.dirname(FILE), 'database.yml'))).result)['production']

filename = "#{db['database']}_dump.#{Time.now.strftime '%Y%m%dT%:%H%M%S'}.sql" remote_path = "#{current_path}/tmp/#{filename}" local_path = "tmp/#{filename}"

on_rollback { run "rm #{remote_path}" }

run "mysqldump -u #{db['username']} --password=#{db['password']} --skip-opt #{db['database']} --complete-insert=true --skip-quote-names --no-create-info > #{remote_path}" do |ch, stream, data| puts data end

get remote_path, local_path

converted = File.read(local_path).gsub(/\'/, '\'\'') File.open("#{local_path}_converted", 'w') {|f| f.write(converted)}

system "sqlite3 db/dev.db < #{local_path}_converted" system "rm #{local_path}" system "rm #{local_path}_converted" run "rm #{remote_path}" end

There is a small problem with \n (new line) characters that on the production server get evaluated as they should. However, on the development machine after the data has been exported from mysql and imported into the sqlite database the \n characters will show as \n on the screen. But for me this is good enough for now.

Back to Apache

I’ve used nginx with php through fastcgi for the php sites and with a mongrel cluster for each rails application on this machine for quite some time now and I’ve been happy with that setup.

However, with the number of rails applications increasing, the number of mongrel instances running increases even faster as each application needs between 2 and 5 mongrel instances.

I see Phusion Passenger (a.k.a mod_rails for Apache) as a way to simplify my setup. Passenger is supposed to do the same magic with Apache for rails as mod_php does for php.

The first step towards this dream setup was to change back from nginx to apache2. As I’ve had to have apache running behind ssl for the subversion repository changing back just meant figuring out how to configure apache to proxy for the mongrel clusters but a bit of googling solved that pretty quickly.

So right now this site is yet again powered by Apache but I’m still running mongrels to serve the rails applications. The next step is to move over to passenger, which I hope to do before the weekend.

I’ll let you know how it goes.

Ruby on Rails 1.2.6: Security and Maintenance Release

The rails core team has released ruby on rails 1.2.6 to address a bug in the fix for session fixation attacks (CVE-2007-5380). The CVE Identifier for this new issue is CVE-2007-6077.

You should upgrade to this new release if you do not take specific session-fixation counter measures in your application. 1.2.6 also fixes some regressions when working with has_many associations on unsaved ActiveRecord objects.

Riding Rails: Ruby on Rails 1.2.6: Security and Maintenance Release

How Oracle Mix was built

We started coding about 3.5 to 4 weeks before Open World. At that point, we still didn’t have hardware and there were a ton of unknowns surrounding jRuby running on the Oracle AppServer (and if it did, what performance would be like). We bit the bullet and went for it. Rails was an essential ingredient to this project. I don’t know of other frameworks that would have enabled us to build this particular application so rapidly.

Oracle AppsLab » Mix, jRuby on Rails, Small Teams, Agile, and it’s Effects on the World

Ruby on Rails is the shit! ;)