I wrote about some of the pitfalls of getting started with Rails in part 1. In this, and subsequent parts, I’ll cover what it was like building my first Rails app.
The app I decided to build was something like an article manager. Not a blog, but somewhere I could store draft articles (written using Markdown) and be able to add/edit drafts along the way.
So specifically I wanted:
- An app that looked reasonable without too much effort spent on design.
- A public interface for viewing the articles and ideas.
- An admin area for working on the articles.
Getting Started with Rails
I decided that if this app was ever going to see production, it would most likely run on Heroku. So I decided to use Postgresql for the database since that’s what Heroku supports.
The next decision was what to do about the admin area. If I built it myself, I would need to be dealing with authentication and login, whereas if I used a gem specially for creating an admin area, there would be a learning curve there too.
I decided to go with the ActiveAdmin gem because I figured it was important to get something up and running quite quickly for my first app. Plenty of time for further experimentation further down the line.
I Struggle With Data First
I know that with Rails, everything ends to start with the model. I struggle with that, so I decided to go with getting at least something to look at working first.
That meant coming up with a layout, and adding some custom styles in the asset pipeline.
Layout and Styles
I already had the Bootstrap support installed. So I borrowed the narrow layout example from the Twitter Bootstrap examples to add a layout to application.html.erb in
I also created
app/assets/stylesheets an imported all the Bootstrap stuff using this:
The example from Bootstrap has some custom styles for the layout, so I added those to
custom.css.scss too. You’ll find them in the
<head></head> section of the example file.
All I had to do in the layout, was in
Making a Controller
You need a controller to get a basic layout working properly, so from Terminal I did:
rails g controller index about contact blog
At this stage, I have no idea whether those actions will be the ones I need, but it seems like a start.
Adding a Route
I removed the
index.html file from the
public folder, and then in
app/config/routes.rb I added:
root :to => 'drafts#index'
Trying it Out
Don’t laugh, but I fired up the Rails server and went to http://localhost:3000 in my browser. It didn’t work of course, because I created the project from Terminal like this:
rails new drafts -d postgresql
So I needed to add my database credentials in
app/config/database.yml and then run
After re-starting the server I now got see my early attempts:
A basic app
So I have a very basic skeleton up and running, with the database configured. In part 3, I’ll continue to flesh out the features I want for the app.