nekkoru/striptease — pull request #1 by JediFreeman (2013-02-27 18:43:07+00:00)
Title: Cleaning up layouts and render issues

Quick summary of changes:

- added Gemfile to easily install required gems via bundler ( http://www.gembundler.com for instructions ) - you can kill this if you do not want it of course :)

- added require 'rubygems' to striptease.rb - my environment by default does not require rubygems, so it was breaking when starting up due to not being able to find sinatra or anything else.

- moved @variables to locals passed into the erb templates. Helps keep the templates self contained and not relying on a @var set and then assumed it can see it - the templates get passed in variables and work with them locally.

- moved get '/archive' ABOVE get '/:id' - THIS ONE IS IMPORTANT - Sinatra looks for a matching route in the order they appear, so when you call /archive it was really calling the /:id route with 'archive' as the id variable, hence why it would break.

- created a layout.erb file in views which has all the stuff index.erb had before - all of your erb calls from the route definitions in striptease.rb will use this layout as the base - you can override it by passing a :layout => 'whatever' variable in the erb call. The layout.erb has a yield call which will yield to whatever template you mention in striptease.rb

- added nil checks to archive.erb and strip.erb and some text so you can see which file is being called.

- removed home.erb as it is redundant to index.erb as it exists now.

There is still more work to do, like checking if you are at the last strip so you do not show a Next button that goes to a strip that does not exist, etc. - Also you will not want to rely on @strip.id +1 / - 1 to get prev/next - database record IDs are not guaranteed to be sequential (for example, if you delete a record in the middle)

Good luck!