Tuesday, February 09, 2010

Heroku Tip; Use a Ping or Uptime Service As a Cron Job.

This is a pass-along tip from Toby Hede (http://stackoverflow.com/users/14971/toby-hede) on StackOverflow. Just give the Ping service the URL of the controller doing the work instead of your root page.

Rails Tip - How Do I See Params From My Forms?

I like to document what my forms are sending to my action methods. So most of the time, I create a method in my controller like this:
def to_export
  render :text => params.inspect
Then I use copy and paste to put the result into my code as a comment.
# {
#   "commit"=>"Upload File", 
#   "authenticity_token"=>"17FvBH+Z4Meni6WvsCdPByrrk751BV9mNklzKDAo2Vc=", 
#   "action"=>"do_import", 
#   "import_criteria"=>{
#     "primary_language_name"=>"Creole", 
#     "secondary_language_name"=>"English"
#   }, 
#   "form"=>{
#     "file"=>"traveling_haiti.txt"
#   }, 
#   "controller"=>"import"
# }

Monday, February 08, 2010

Another Fix for EMAIL not authorized to access APP

I wanted to change the primary email associated with my Heroku account. So I removed the email from the authorization list. The next time I pulled from git, I got the following error:

heroku@david-medinets.otherinbox.com not authorized to access crisiscamp-translation
The email address is pulled from your public/private keys which can be recreated using the following command:
ssh-keygen -t rsa -C EMAIL

Sunday, February 07, 2010

Using Formtastic Without ActiveRecord

Let's start with a model:
class PrimaryLanguage
  attr_accessor :name
  def initialize(name)
    @name = name
Then create an object in a controller:
class AbcController < ActionController::Base
  def aaa
    @primary_language = PrimaryLanguage.new('English')
Design a form:
<% semantic_form_for @primary_language, :url => select_primary_language_path, :html => { :id => 'primary_language'} do |form| %>
  <%= form.input :name, :as => :select, :collection => @languages, :required => false, :label => "Primary Language:<br/>", :include_blank => false %>
<% end %>
And finally handle the user's input;
class XyzController < ActionController::Base
  def bbb
    primary_language_name = params[:primary_language][:name]
    # do something