DEV Community

Eben Eleazer
Eben Eleazer

Posted on

Things Are Really Off the Rails Now!

Rails Project App- MyScene

Alt Text

It's a dumb name, but I couldn't think of anything better on short notice

Time for another project

This project was built with Rails, and is by far the most extensive. I tried to use as many features as I know, including layouts, partials, scopes and helpers to name a few.

About the application

The idea behind MyScene is to help people find local bands and concerts. Artists can create an account and upload information about their concerts and the venues that they play at. Even without making an artist account, users should be able to see and search for concerts (but not edit anything).

Building the Models

The app has 4 models: Artists, Venues, Concerts and Addresses. Concerts belong to both Venues and Artists, and Addresses belong to Venues. This means that we can set up many to many relationship for Artists to have many Venues through concerts and vice versa. we also have a one to one relationship for Concerts to have an Address through Venues.

Alt Text

Looking at the schema, you can see that the Artist class also functions as the "User" class, since we expect that musicians will be the ones creating concerts.

All of the models have validations to make sure that they have the minimum amount of information to be useful before they are saved. There are also custom validators on Venues to make sure they have an address instance attached and on Concerts to make sure the start time is before the end time.

Controller Actions

The controller actions are pretty much what you'd expect, they get the proper model instance or collection and pass it on the the views. One notable thing are the before actions defined in the global application controller that requires a user to be logged in to edit, create or delete venues and concerts, and one defined in the Artist class that only allows editing and deleting of the current artist.

Alt Text

Views

The most important feature of the views is the search bar in the main layout. This is connected to the Concert index action and allows any user, logged in or not, to search for concerts by name, artist name or venue name.

The views use partials for the forms and collection items, and helpers to generate more dynamic html.

Complications and Lessons

This was my first full rails app, and It was mostly painless compared to the Sinatra and the CLI app. One thing that kept giving me problems was the views breaking when the controller couldn't find an appropriate model. Doing this project taught me a lot about protecting against calling methods on objects that might be nil.

So that's my latest project

Next I'm moving on to JavaScript!

until then...

Discussion (0)