GitXplorerGitXplorer
a

sinatra-starter-app

public
0 stars
1 forks
0 issues

Commits

List of commits on branch master.
Unverified
c11085f88962ff3958bfeea5f870c8d1ba7a3ec1

Add unindent helper to string class

aadammcarth committed 11 years ago
Unverified
79ea86f02cbd84da0bb1e74a91db43bad2189a29

Fonts don't belong in the assets pipeline.

aadammcarth committed 11 years ago
Unverified
5b6c84383f8e0d72cb375b2d6b822e4eaed6ec05

Fix uploads path error

aadammcarth committed 11 years ago
Unverified
1909d6c44fcaa389c60d33afe79bf1b4d84ec6b8

Remove unneeded files and folders

aadammcarth committed 11 years ago
Unverified
2226c865fafbac5f9cb112183c824eb1d5230bc1

Refactor query string code by 50%. Works awesome.

aadammcarth committed 11 years ago
Unverified
1076d95898ca7d3a631bdc1e70406e7d379d187b

Add very effective query string helper

aadammcarth committed 11 years ago

README

The README file for this repository.

Use this basic Sinatra Starter Application every time you start a new project. It works right out of the box, and only requires a tiny bit of configuration to get your development project up and running.

What it's good for:

  • Perfect backbones if you're starting a dynamic sinatra web application.
  • Created for use with MySQL.
  • People who want an easy starting template that's extremely flexible and contains good practises.

What it's not good for:

  • Not as great for static websites. This template is database driven, and the file structure and configuration is not really suited to an application that rarely uses dynamic content. If you're on this boat, take advantage of Sinatra's awesome lightweight nature and keep it basic.
  • Haml junkies and people wearing cheap suites.

Installation:

  1. Configure The Databse:
    1.1. Change config\database_example.yml to config\database.yml.
    1.2. Add your MySQL database settings to the database config file.
  2. Install The Gems:
    2.1. CD to your project folder using terminal/command prompt.
    2.2. Run bundle install.
  3. Oh... that's it. Start your server by running either rackup or ruby app.rb.

Shotgun and Tux?

This template uses 2 development gems by default, shotgun and tux, which you may not have come across before:

  • If you're a Mac or Linux user, start your server when in development by using shotgun. This means you don't have to restart the server each time you wish to refresh the page to see your changes. Sorry, this gem doesn't work for Windows users.
  • The tux console allows you to run ruby code in your apps environment. Open a fresh terminal/command prompt and cd to your project. Simply run tux like so...
    Once in the Tux console, we can talk to our App in ruby code (assuming we have a post model):
$ tux
>> Post.count
3
>> loadingBay = Post.new(title: "Foo", body: "Hello World")
>> loadingBay.save
>> Post.count
4

Flash Messages

The sinatra-flash gem also comes default with this template. Almost every dynamic app has a use for them. To use flash messages, follow the example below:

post "/posts"
  @post = Post.new(params[:post])
  if @post.save
    flash.next[:success] = "Your post was added succesfully!"
    redirect "/posts/#{@post.id}"
  else
    flash.next[:error] = "Oops. Something went wrong. Please fix any errors and try again!"
    erb :"posts/new"
  end
end

###Asset Pipeline The asset pipeline works exactly the same as it does in Rails. This template uses sprockets, so if you're unfamiliar with it - it's probably worth your while to read the documentation. The way it's setup now, anything you put into assets/stylesheets will get automatically added to your layout. For stability reasons, files in assets/javascripts need to be manually included in the application.js file (you can change this of course).

###Rendering Partials Again, a helper method has been added to simulate rails-style partials. To use a partial with this template, use the exact same technique you use in Rails:

# views/_login.erb
I'm a login form :)

# views/index.erb
<%= render :partial => "login" %>

# Browser Output:
I'm a login form :)

QITYMA (Questions I Think You Might Ask):

What is the point of step 1.1? Why don't you just upload the proper filename, database.yml?:

Should you ever decide to upload your finished application to GitHub, I've made sure that the real database.yml file is ignored so that people can't access your MySQL configuration in plain text. This demo app is no different, so I had to add _example to prevent .gitignore from hiding it.

Bundle Install fails due to MySQL2. How do I fix it?

Try seperately installing the MySQL2 gem like this (sub in the real path of your lib folder):

gem install mysql2 -- --with-mysql-lib=/usr/lib/mysql/lib