Learnin’ Ruby – #2. Develop a simple Ruby on Rails application.

May 29th, 20119:00 am

0


Well I created a Ruby on Rails Blog application.
You can find it hosted on Heroku here: http://jameseisenhauer.heroku.com/

It could use some more features, but generally it completes the story of blogging.

Well how did I get here……

First!  Like any newb programmer I looked for a tutorial.  The http://rubyonrails.org site recommend  http://railsforzombies.org/ .  So why not start there.  Well the site is cute and they did a nice job….here it comes….but it is sooo slow to get through and while I think the “programming” via the website is “neat” you don’t get to build anything and that is mostly why I code is because I like creating something….like long run on sentences.  If you were new to programming I think it would be a good exercise to go through, but if you are a seasoned developer I fear you may find it slow as well.

Well not happy with that tutorial I search for something that showed me the steps to create a Ruby on Rails application, but let me pass over the tedious simple stuff, and I found How to Create a Blog from Scratch Using Ruby on Rails .

Phil McClure did a great job with this article.  However I have seen in this article and others an odd method to run rails code via the command line.  I think it might be a rails 3.0 thing, since this article is 2 years old, but I am not sure.

In the article it states to run this:

1
ruby script/generate scaffold post title:string body:text

however the more recent tutorials I have gone through state to execute  it like:

1
rails generate scaffold post title:string body:text

I didn’t try the old way so I am not sure if it works.

I got the initial scaffolding set up and working and then was like…..I want to implement my fancy design I created during the setup.  I started looking at all the views that got created and thought….no way can they expect me to edit all of these…this is supposed to be easier.  Google “ruby on rails global layout” and boom goes the dynamite!  A simple edit of \app\views\layouts\application.html.erb and now my entire site was using the same design!

Well sorta….last time I thought I learned about relative image locations in rails, but I was wrong…all of a sudden I had images in my design not working!  I searched and I found this concept of tags in the rails api.

1
image_tag "bg22.jpg"

the rails api handled everything for me.  The html for the img as well as the correct path!

Next I didn’t like how you could submit a blog post and leave things blank so adding a single line of code:

2
 validates_presence_of :body, :message => "can't be blank"

and rails makes sure the field isn’t blank…nice!

So happy with everything I checkin’ my code and push it to heroku and…

I was like…..uhhh what went wrong??…..who has been notified??….how long will it take for this person to look at my error??

After waiting for 2 minutes to see if a Heroku customer service agent chat would show up on my desktop…(one can dream right?).  I started thinking….maybe that is my error….something from the rails api since it knows it is in production??  I do find out this is a rails convention, which caused another issue.  How do I troubleshoot this?  I mean my code is in the cloud!  I do I troubleshoot the cloud?!?  Well easy heroku says:

3
heroku logs

I see the error that a table can’t be found…and realized during my simple deployment all of the “magic” didn’t happen…I don’t have a database.

I try a:

4
heroku rake db:create

and it tells me the database already exists….so I think…must be just the table missing and I find this command:

5
heroku rake db:migrate

heroku tells me that it created my tables! I browse the site and it works perfectly!

Next stop more features, better IDE then notepad and rails testing with maybe some cucumber thrown in.

Related posts:

Tags:  , , ,