
Ask YC: I built this to learn Rails in 2 days. What do you think? - dcurtis
I sat down last week and felt determined to learn Rails as quickly as possible. I skimmed the Agile Web Development With Rails book and got to work on a fuel-calculating mini-app. Time to completion: 2 days with very little sleep.<p>Site: http://fuel.dustincurtis.com<p>While I was building the site, I kept wishing that I could look at an app's code in its entirety for help with syntax (searching google gave me nothing), so here's the code (it's probably very shitty):
Code: http://itsalltaken.com/fuelcode<p>What do you think of the design and implementation?<p>PS. I need to add in a bunch of higher-level validations to prevent people from using obscene numbers/dates/etc. Also the mobile version isn't quite done yet.
======
crescendo
The design is very clean and appealing. Also the function is user friendly.
Some cursory testing uncovered the following bugs:

Location: /

    
    
       Sign up
          
          - "email address" should select or disappear on click.
          
          - password should be empty.
          
          - login cookie?
    

Location: /account/login

    
    
          - Tabbing should go from the "Login to fuel" field to the password field. Currently focus vanishes on tabbing from this field.
    

Location: /fuelings

    
    
       - Past fuelings: The time calculation is wrong. It shows 21 hours for an edit I made ~5 minutes ago.
       
       - /edit
       
          - commit button still says "Add this fueling". Should say something like "Update".
       
          - values are old (e.g., change the "Gallons" value, and click the button. Dashboard shows new value. Click to "edit" the fueling again, and old value still shows here).
          
          - Date text box allows invalid date values. Replaced "JANUARY" with "PLUTO", and date disappeared from dashboard. On the next access of dashboard, got a "NoMethodError" on line #68 of fuelings/index.html.erb.
    

I was never able to access the app again after the last error.

~~~
dcurtis
Wow, thank you so much.

The javascript stuff to make the forms pretty (and disappear when active) is
the very next step. Login cookie is next.

account/login tabbing: I'll fix that. Thanks.

The time calculation is based on midnight of the date you select on the Add
Fueling page. I'll add the time of day, but I don't think people keep track of
their fueling habits that closely.

Regarding editing, I've removed your NULL date, so you can log back in. I'll
add verification to prevent that from happening in the future.

Again, thanks. Awesome.

------
mechanical_fish
Very nice visual design.

Your code will improve at once if you read a Ruby book. For example, you
confess to being confused in your fueling.rb model file --

<GOBBLEDEGOOK>

\-- where you define a class method on the Fueling class, then set an instance
variable (@current_id). I believe this will set @current_id in the scope of
the Fueling class. Then you define a Fueling instance method (validate) and
try to read @current_id inside it -- but it fails, because when you're in an
instance method @current_id refers to a variable in some actual Fueling
_object_ , not to the @current_id that's in the scope of the Fueling _class_.

</GOBBLEDEGOOK>

You may have no idea what I just said. Even experts can get lost in Ruby's
class hierarchy. So get a Ruby book and it will help you sort out the Ruby
approach to OO programming.

People seem to like "Ruby for Rails", and its author is smart. The Pickaxe
book ("Programming Ruby") is more famous and I liked that just fine, too.
(Don't tell Zed Shaw.) If you're not already intimately familiar with another
OO language, you might _not_ want to learn Ruby from _Why the Lucky Stiff's
_Poignant Guide to Ruby_ (with cartoon foxes!)... although that's what I did.

P.S. Just _today_ I had my accountant explaining to me the importance of
separate tracking for "business" miles that I drive for my company, as well as
tracking total miles driven. Food for thought. Just don't offer that feature
if you plan to take the service down sometime during a tax year...

~~~
Zak
I've been finding a bunch of errors[0] in the Pickaxe book lately. If you're
using it as a reference, and finding that things don't behave as expected,
double check at ruby-doc.org.

[0] or at least differences between Ruby 1.6, which is covered in the book,
and 1.8, which most people use.

------
marionogueira
Good job dcurtis!

My friends and I built the app in the link below with Rails and in 48h too.

<http://pagestacker.com>

ThereXs an interesting story behing its development.

It was in september. At the time, we were pretty much still learning about
Rails. We had heard about a contest in which participants should build a
complete web app from scratch in 48h using Rails. It was called "Rails
Rumble".

<http://www.railsrumble.com>

After those initial 48h, there was a 14 days period of voting that was open to
the public in order to choose the "best" apps (whatever that means). Although
we led the voting almost since day one, the organization decided to disqualify
most of our votes and gave us an "honorable mention".

In the link below you can find a Twitter feed with the ranking results that
were published as the voting developed.

<http://twitter.com/railsrumblerank>

We still donXt fully understand the reasons why the organizers decided as they
did. Maybe it had something to do with the fact that weXre from Brazil in our
team ("I didnXt even know brazilians had computers" =)). Who knows...

Anyway, what matters is that weXre seing some traction among users, not only
in Brazil but around the world (not much, but some), and we must decide if we
should invest more and try to enhance the app.

What weXve found is that most users never heard anything about the segment to
which the app belongs, much less about its leader, which has only some 3
million registered users around the world.

So, IXd really appreciate some honest feedback about it.

Thanks!

------
axod
15.3 mpg? Jesus christ get some better cars!

------
aaroneous
I know people who meticulously keep pen & paper records of their mileage...
I'm sure those people would love this site.

It's very elegant in its simplicity - well done!

Bonus points for being from Santa Rosa. I spent four awesome years living
there. Pepe's still has a special place in my heart for best vegetarian
burrito, evar.

------
carpal
Not bad for a first shot. One suggestion is to use the "fat model, skinny
controller" way of thinking. It'll help clean up your code significantly.

[http://weblog.jamisbuck.org/2006/10/18/skinny-controller-
fat...](http://weblog.jamisbuck.org/2006/10/18/skinny-controller-fat-model)

I've pastied an example of how this approach should help.

<http://rafb.net/p/P4YMM359.html> (Pastie.caboo.se is down now for some
reason, so this is good enough for now)

Generally, the only major issue I see throughout is the repeated
Fueling.find(:all) calls. Not only will that hit up the database quite a bit
(Rails 2.0's query caching would help a little, but that's beside the point),
but it would take up a crazy amount of memory once you get a lot of fuelings
in the system.

Keep at it!

------
raju
Wow! Great design, nice clean look to it. congratulations on your first rails
app. To add to mechanical_fish's comment, David Black's "Ruby for rails" is a
good book. Another good book which I have not read, but have heard great
things of, is Peter Cooper's book. Again, congratulations! Great work...

Along a similar note, I wish I could work along these lines. I tend to be too
much of an academic, and spend endless weeks reading about whatever (rails in
this case) and never actually get down to implementing much, then get
attracted to the next new shiny toy, and move on. So from my perspective,
great job!

------
tx
Looked at your code: looks very much like mine :-) I suppose it's a good thing
since the mantra of opinionated Rails means just that: "stay on it".

I saw your confusing comments for non-working Fueling validate(). Why don't
you just check for nil there? It's always nil for 1st time users, no?

------
joshwa
For the code hilighting part, you could probably hack something together with
<http://pastie.caboo.se/>

------
zeantsoi
I think there's an underlying sentiment here: design is fantastic. Great job!

------
jkush
Nice job. Looks like you had some fun doing it!

------
dkimbell
Two days, eh? I'm impressed. It looks good!

------
nickb
Neat! Love the design!

PS: Could you add km/h and L as well?

~~~
dcurtis
Yup, that's on the list of things to do!

------
nkohari
Nice work. I like the design!

------
mhidalgo
where are you hosting it ?

~~~
dcurtis
Dreamhost. And they're pretty good about it, too.

~~~
davidw
Well... it's down right now at 9:24 CEST. Or at least 'loading...' is taking
forever.

~~~
dcurtis
Yeah, <http://dreamhoststatus.com/>

They're rebooting after a failed update or something.

edit: it's back up (12:41am pst)

------
chaostheory
I like the clean design

~~~
dcurtis
Thanks!

------
ahrhan
pretty neat idea.

