Archive for the 'ruby on rails' Category

Pretty Rails Logs in Windows

Friday, November 21st, 2008

Viewing Rails logs from Windows commandline is ugly. I’ve been looking for a solution for awhile only to find one was right under my nose. Following the advice of this post I remembered that Git on Windows uses MSYS + MinGW. Just open up the Git Bash prompt shortcut in the start [...]

How to send test mail with ActionMailer

Thursday, September 25th, 2008

Setup your ActionMailer. I’m using Google Mail for my stuff: http://www.rubyinside.com/how-to-use-gmails-smtp-server-with-rails-394.html
ruby script/generate mailer testmailer
Add this code to testmailer.rb (Testmailer < ActionMailer::Base)
def test_mail(to)
subject “My first email!”
recipients “#{to}”
from ‘test’
charset “utf-8″
content_type ‘text/html’
body “Testing one two three…”
end

ruby script/console
Testmailer.deliver_test_mail(”you@yourdomain.com”)

ActionMailer API doc

Month name helper passing month number for Rails

Wednesday, June 18th, 2008

I couldn’t find a helper in the API to just display months if you’re storing them as numbers (1-12) so I made one.
Add this helper code to your application_helper.rb or other appropriate *_helper.rb file.

def monthname(monthnumber)
if monthnumber
Date::MONTHNAMES[monthnumber]
end
end

Use it in your view like this:

< %=h monthname(item.month) %>

Using ReCAPTCHA on Rails

Sunday, April 20th, 2008

For TYWYK I wanted to prevent spam early on, but still allow anyone to post. I chose using a CAPTCHA. I’m using Jason Perry’s ReCAPTCHA plugin which uses ReCAPTCHA.
It’s pretty straightforward. Just read the README and all the comments on agilewebdevelopment and you should be good to go!
Only gotcha that I ran [...]

Custom validation with rails: words with more than 26 characters

Friday, March 21st, 2008

This validation goes through and validates each individual word in your string. This goes in whatever model you’re validating. “Subject” can be any of the symbols in your model and doesn’t need the : in front of it.

def validate
if subject.split.any?{|w| w.length > 26}
errors.add(:subject, “cannot have words more than 26 consecutive characters”)
end
end

Custom errors on validations for Rails

Wednesday, March 12th, 2008

The default Rails way of doing validate error messages is sort of silly. It works, but it doesn’t work that well. You can iterate through all the error messages in a very constrained way (error_messages_for) or you can display errors on fields one by one (error_message_on). I kind of want functionality from [...]

Create a preview page in Ruby on Rails

Friday, February 29th, 2008

I searched so long and hard for this and now feel compelled to post it here with some good keywords so that others can find it.
I wanted to create a preview page for my form submission in rails. I found a couple people who had tried some stuff, but none of the examples were [...]

multipart in start_form_tag

Tuesday, April 25th, 2006

I was using file_column today in Ruby on Rails and ended up with the error:
Do not know how to handle a string with value ‘my_fruity_graph.png’ that was passed to a file_column. Check if the form’s encoding has been set to ‘multipart/form-data’.
The problem is obvious.. enctype=”multipart/form-data” was not part of the form_tag.
Now how to get that [...]

Rails on Fedora + Plesk Fiasco

Tuesday, March 28th, 2006

Wow. I have spent at least the last week trying to get rails to work the way I wanted it to on my Fedora box with Plesk. This morning I finally got it working. You may be very interested in this article if you’re wondering about any of the following:

The mysterious Application [...]

Oh how I hate Internet Explorer

Sunday, March 12th, 2006

Internet Explorer is such a worthless piece of shit. Nobody should use it as a browser. Ever. For any reason whatsoever.
For those of you who are not web developers I’m sure you won’t understand my pain, but let me assure you that if you ARE an Internet Explorer user, webdev or not, [...]


I've left the country and this site is just an archive! Check out my trip blog!