Code Prostitute

the sordid details of my career as a code prostitute

Archive for the ‘Rails’ Category

undefined method `set_cookie’ 2.3.3

without comments

If you’re using “Tamper-proof cookies” like I am following this tutorial,
and recently moved to rails 2.3.3, you may be getting this error:

NoMethodError (undefined method `set_cookie’ for #):

It actually isn’t so much to do with Tamper-proof cookies, as it is that set_cookie has been deprecated in favor or http_only=.

So, if you’re having this issue, open lib/tamper_proof_cookie_jar.rb and search for “set_cookie” (should be line 38).

replace with this:

http_only=options

Or, anywhere you were using set_cookie, use http_only= instead.

Restart your app server (apache, mod_rails, mongrel…) and it should work for you now.

Written by codeprostitute

October 14, 2009 at 12:39 pm

Posted in Rails, Ruby

Tagged with , , ,

Snow Leopard Install, Ruby on Rails MySQL dev machine

without comments

Here are some helpful notes if you’re upgrading to Snow Leopard (SL), and you do Ruby on Rails / MySQL development.

From a dev perspective, there are a number of things that changed with the update to Leopard.

On the Snow Leopard DVD, under “Optional Installs”, install “Xcode.mpkg”. Use all default options.

If you were using MacPorts,it will need to be updated.
Install the latest for SL (1.8.0): http://www.macports.org/install.php
Then, follow this guide to update MacPorts – I suggest doing the manual method to make sure you don’t install stuff you don’t really need. I installed coreutils, and it installed pretty much everything else I needed. If you’re running MySQL through MacPorts, don’t add it back. You’ll be guided by the Ruby on Rails guide to install the 64-bit version next.
The user will probably want wget… installing that gets you openssl, zlib.
http://trac.macports.org/wiki/Migration

Ruby on Rails__
This is an excellent guide, do follow this:
http://weblog.rubyonrails.org/2009/8/30/upgrading-to-snow-leopard Before you read this post and give up, look up your errors in the comments. I had 2 or 3 issues and what do you know? Others had the same issues, I followed a few of the comments where people address others’ issues and viola… working nicely now. Another tip for MySQL: When you install MySQL from mysql.org, be sure to pick the right one.. I kept getting the PowerPC one because it was at the end and had a “64″ on it… I realized I needed the other one.

This should get you through most of the changes for Ruby on Rails, and a good start on developer machines in general.

Post any questions you have.

Cheers,
Richard

Written by codeprostitute

September 26, 2009 at 12:19 am

Ruby / Rails: Remove Extra Space

without comments

…or anything else you want from a string.


" myemail @ address. co m ".gsub(/\s/, '')

gsub() substitutes all instances found (g = global), if you just want to substitute the first instance use sub()

Or, if you want to trim the whitespace from each end:


result = " myemail@address.com ".strip

To just trim the whitespace on the left or the right, use these (respectively):
lstrip()
rstrip()

Written by codeprostitute

May 1, 2009 at 12:16 pm

Rails Deployment

without comments

Do yourself a favor and use mongrel cluster with Capistrano deployment… what does all the bruhaha mean? A happier life, my online friend.

Time For A Grown-Up Server: Rails, Mongrel, Apache, Capistrano and You

Written by codeprostitute

July 18, 2007 at 1:19 am

Rails SQL query

with one comment

I needed to know the highest single (integer) value from a table:column. Not having done this before in Rails, my first intuition was to write something that would create a connection with the db, run a SQL string in a query, return the results to a variable, look in the variable if it came back as an array or some other object and get my value.

As always, I was pleasantly surprised to find that I could run a single query and get my value in a very readable, succinct statement:

@total_pages = ActiveRecord::Base.connection.select_value('SELECT MAX(page) FROM questions')

Beautiful.

Written by codeprostitute

April 25, 2007 at 8:22 pm

Posted in Rails, Ruby, SQL