First Webapp

During my lunch break today, I opened up Ruby on Rails Tutorial and walked through setting up another first time app.

So this is my 2nd app i’m working on.  I wanted to actually do something… so I decided to get something simple going and publish via Heroku.

So what’s Heroku?
Heroku is this awesome cloud service, that’s free, if  you’re just testing your apps.  you go to heroku.com and set up an account… then you run a rails gem like: gem install heroku
and that will install it.

The idea is this:
1. you write some code
2. you commit the code locally with git commit
3. you push the commit to a remote git repo (i.e. github.com)
4. you make a call to Heroku to pick up the git repo and publish it.

I hit a few snags from the book though.  The book didn’t tell me I had to change the gem sqlite3.  Heroku doesn’t like it. The solution was to go into the Rails Gemfile and do something like this:

group :development, :test do
   gem “sqlite3”
end

If you don’t set up a dev group like that, then it tries to compile sqlite3 on Heroku and since it has it’s own db structure it will fail and error out (the error would be “an error occurred while installing sqlite3….”

So here’s my webapp:
http://peaceful-castle-5270.herokuapp.com/users

Heroku makes a random name for your webapp.  That /users is the code I comitted and published. it allows users to be created based on their email address.

So how did I do it?

Well I cheated somewhat.  I used scaffolding.  In Rails there’s a scaffolding option.  It will build out a structure for your application.  All I had to do, was call a Users model with the scaffolding and it built it out…
rails generate scaffold User name:string email:string

That one command did all of this.  It created the User model and set up a name and email variable as a string the user inputs.  It added in all the good stuff.

Once done, you run a rake migrate, like:
bundle exec rake db:migrate

Add this to Git: git add .
Commit with git: git commit -m “something”
Push to github (should have defined this already): git push
If you have created the Heroku space, you run:
heroku create
Publish with Heroku: git push heroku master

You’re done.  Go to the url

Leave a Reply

Your email address will not be published. Required fields are marked *