Giter Club home page Giter Club logo

meetups-in-the-ocean's Introduction

Sinatra Active Record Starter Kit

This template provides a basic Sinatra application that includes:

Getting Started

# Clone down this template
git clone https://github.com/LaunchAcademy/sinatra-activerecord-starter-kit.git <YOUR_APP_NAME>

# Move into your app's directory
cd <YOUR_APP_NAME>

# Install all the gems
bundle install

# Remove the old git history and start your own
rm -rf .git && git init && git add -A && git commit -m 'Initial commit'

# Copy the example database.yml file over to its intended destination
cp config/database.example.yml config/database.yml

# Once you've edit the database.yml file as needed, you can create the database
rake db:create

Configuring Your Database

Note the last two steps above. This template is set up for using a PostgreSQL database. You will need to create a config/database.yml for the application to connect to the database successfully.

Once you've created and configured the config/database.yml file, you can create the database with the rake db:create command.

Rake Tasks

This template uses the sinatra-activerecord gem, which provides the following rails-like rake tasks:

rake db:create            # create the database from config/database.yml from the current Sinatra env
rake db:create_migration  # create an ActiveRecord migration
rake db:drop              # drops the data from config/database.yml from the current Sinatra env
rake db:migrate           # migrate the database (use version with VERSION=n)
rake db:rollback          # roll back the migration (use steps with STEP=n)
rake db:schema:dump       # dump schema into file
rake db:schema:load       # load schema into database
rake db:seed              # load the seed data from db/seeds.rb
rake db:setup             # create the database and load the schema
rake db:test:prepare      # Prepare test database from development schema

If you are having trouble with any of these commands, try prefixing them with bundle exec.

Source

Flash Notices

Uses Sinatra Flash

Flash messages allow you to send information across page redirects. However, only short messages may be sent. Long messages or large objects tend to result in the Flash messages being cleared. In the /app/views/layout.erb, a message box for flash[:notice] has already been added.

Example:

# app.rb

post '/books' do
  # do some logic like save something to the database
  flash[:notice] = "Your book was saved!"

  redirect '/books/all'
end

get '/books/all' do
  # Some code or logic to get all books

  erb :'books/index'
  # Flash message will appear on this page
end

# HEADS UP - flash does not work if returning a view
get '/books/all' do
  flash[:notice] = "This will not appear on the page."

  erb :'/books/index'
  # No flash message will appear until you navigate to a new page or the page refreshes.
end

Shoulda Matchers

Uses Shoulda Matchers

Shoulda Matchers allow for easier testing of Model associations in your unit tests using RSpec.

Example:

# /spec/models/user_spec.rb

require 'spec_helper'
# In this example, a user can have many books,
# but may only belong to a single library.
describe User do
  it { should belong_to :library }
  it { should have_many :books }
end
# /app/models/user.rb

class User < ActiveRecord::Base
  # Note the difference in "belongs_to" here vs. "belong_to" in the spec test.
  belongs_to :library
  has_many :books
end

Valid Attribute

Uses Valid Attribute

Valid Attribute allows for the rapid development of tests for validations in your models.

Example:

# /spec/models/user_spec.rb

describe User do
  it { should have_valid(:username).when("valid_username", "another_valid_username") }
  it { should_not have_valid(:username).when('', nil) }
end
# /app/models/user.rb

class User < ActiveRecord::Base
  validates :username, presence: true
end

meetups-in-the-ocean's People

Contributors

smkopp92 avatar

Watchers

 avatar  avatar

meetups-in-the-ocean's Issues

What if I don't have a boat

Hello yes I would like to have meetups in the ocean but I don't have a boat. Can you add support for land?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.