MetaGreg

writes code that writes code for food

Archive for the ‘Business’ Category

Rails 3 upgrade part 3: Code fixes, views, and forms

with 2 comments

This is part 3 of my Rails 2 to Rails 3 upgrade experience. Part 1 is about the initial code upgrade and getting the application to boot while part 2 deals with routes. While Part 2 is mainly about routes, getting it work involved changes in other parts of the code which I’ll share this time. So while you are updating your routes, you may need to check this post in between changes.

Update ApplicationController

After regenerating your application with rails (i.e. rails new appname -d dbadapter), your ApplicationController would look like this:

class ApplicationController < ActionController::Base
  protect_from_forgery
end

There’s no need to panic because rails:upgrade:backup made a copy of the controller to application_controller.rb.rails2.

If you have a lot of helper modules, you’ll most likely have this code in your Rails 2 ApplicationController:

helper :all

If you encounter a missing method error while monkey clicking your application, you probably forgot to update your Rails 3 ApplicationController.

Update ApplicationHelper

The ApplicationHelper module was also modified by the rails upgrde. So don’t forget to update this, too.

RAILS_* constants are deprecated is not entirely true

When you run rails:upgrade:check, it will list items you need to update including deprecated code. There is no need to change these as the word ‘deprecated’ means but I encountered several “can’t convert nil into String” errors.

rake rails:upgrade:check
(in /mnt/hgfs/greg-mini/dev/projects/propsify)
Deprecated constant(s)
Constants like RAILS_ENV, RAILS_ROOT, and RAILS_DEFAULT_LOGGER are now deprecated.
More information: http://litanyagainstfear.com/blog/2010/02/03/the-rails-module/

The culprits:
  ...

The weird part is some constants are just doing fine. In any case, here are the conversion:

RAILS_ROOT  -> Rails.root
RAILS_ENV -> Rails.env
RAILS_DEFAULT_LOGGER -> Rails.logger

You can also check your environment the Ruby way:

# before
if RAILS_ENV == 'production'
  ...

# Rails 3
if Rails.env.production?

Output strings are automatically escaped

We should all be rejoicing that Rails is now serious about XSS protection except now your pages have become ugly with all those HTML tags. For example the code below will not give you a clickable link.

- signup = link_to('create one here', signup_path)
= "If you do not have an account, #{signup}."

To fix this, use the raw() helper.

= raw "If you do not have an account, #{signup}."

Too bad for me, I got tons of views that were coded like this.

Check for ‘concat’

A popular technique to simplify your view code is to use content blocks. You create a helper that takes a block and wraps it in some HTML tags. A simple implementation would look like this:

module LayoutHelper
  def main_column(options={}, &block)
    # calls column()
  end

  def column(options={}, &block)
    # concat is not needed in Rails 3
    concat content_tag(:div, capture(&block), options)
  end
end

# in your view
- main_column do
  = render 'form'

This works fine in Rails 2 but in Rails 3 the block gets outputted twice. concat is the way to output text in a non-output block (i.e. <% %> in erb) but it seems like erb blocks in Rails 3 do not need concat.

Helpers with blocks

Before Rails 3, form_for or fields_for use non-output syntax; it means no equals sign.

# erb
<% form_for @offer do |f| %>
  # ...
<% end %>

# haml
- form_for @offer do |f|
  # ...

In Rails 3, it should now be written as an output block.

# erb
<%= form_for @offer do |f| %>
  # ...
<% end %>

# haml
= form_for @offer do |f|
  = f.fields_for :items do |ff|
    # ...

The rule is if the method is expected to return a string, it should use the output syntax. If it just buffering the returned string like content_for, it should NOT have the equals sign.

Previous: Rails 3 upgrade part 2: Routes
Next: Rails 3 upgrade part 4: Prototype helpers and Javascript

Written by Greg Moreno

August 13th, 2010 at 5:12 pm

Posted in Business

Tagged with ,

What is the right way to build a startup?

without comments

  • Define a market problem that you believe you can solve
  • Research this market by doing market sizing, looking at existing products, talking to customers and deciding how you will make money
  • Validate that you can make money before starting. This means looking at what your buyer pays for similar products now, what the history of other people who have tried to monetize in this way have experienced, what your costs to acquire customers will be and what you believe you can make over the customers’ lifetimes. These are all assumptions – nothing more. I believe passionately that if you don’t do a financial model you shouldn’t spend any time or money building a product. You want to talk about the ultimate “fail fast” – how about if you fail before you’ve spent any money building product because you validate there isn’t a big enough market or you can’t make money?
  • If you believe there is a market then build a prototype product that you can show customers, investors and potential employees.
  • From there build the MVP (minimum viable product). I believe in launching with a small set of features and learning from the market before you spend too much money building out a feature rich product or before you put serious capital to work.
  • If you validate that there’s a market then go for it! If you don’t believe that your product is resonating then pivot and find one!

from Mark Suster’s post “Why The ‘Fail Fast’ Mantra Needs to Fail“. Check out his article because it’s a well-written post against the “Fail Fast” idea.

Written by Greg Moreno

April 7th, 2010 at 10:21 pm

Posted in Business

The secret history of Silicon Valley

without comments

from YouTube’s description:

Today, Silicon Valley is known around the world as a fount of technology innovation and development fueled by private venture capital and peopled by fabled entrepreneurs. But it wasn’t always so. Unbeknownst to even seasoned inhabitants, today’s Silicon Valley had its start in government secrecy and wartime urgency.

In this lecture, renowned serial entrepreneur Steve Blank presents how the roots of Silicon Valley sprang not from the later development of the silicon semiconductor but instead from the earlier technology duel over the skies of Germany and secret efforts around (and over) the Soviet Union. World War II, the Cold War and one Stanford professor set the stage for the creation and explosive growth of entrepreneurship in Silicon Valley. The world was forever changed when the Defense Department, CIA and the National Security Agency acted like today’s venture capitalists funding this first wave of entrepreneurship. Steve Blank shows how these groundbreaking early advances lead up to the high-octane, venture capital fueled Silicon Valley we know today.

Written by Greg Moreno

March 16th, 2010 at 10:36 am

Posted in Business

Why ideas are worthless

without comments

Awful idea = -1
Weak idea = 1
So-so idea = 5
Good idea = 10
Great idea = 15
Brilliant idea = 20

No execution = $1
Weak execution = $1000
So-so execution = $10,000
Good execution = $100,000
Great execution = $1,000,000
Brilliant execution = $10,000,000

To make a business, you need to multiply the two.

—Derek Sivers, president and programmer, CD Baby and HostBaby

Read more practical software and business advice at Getting Real

Written by Greg Moreno

January 14th, 2010 at 8:05 pm

Posted in Business,Getting Things Done

Tagged with

What kind of startup makes sense for you?

with 2 comments

Traditional. VC-backed and a mix of seasoned executives. Everyone agrees that revenue or profit can come months, sometimes years after launch.

MicroISV. You (or with another developer) bootstrap your business while consulting or working for another company. You wear many hats and put in 60-hour weeks.

Side Project. You work on a small but persistent pain. You work on something cool but don’t have the desire to make it a full-fledged startup. Could be a starting point for another startup.

Open Source. You have no problem including “Software should be Free” and “We want to Make Money” on the same page of your business plan.

Join the discussion in Facebook.

Written by Greg Moreno

January 10th, 2010 at 11:45 pm

Posted in Business

Tagged with ,