Git Product home page Git Product logo

sinatra-memoapp's Introduction

sinatra版メモアプリ

インストール

必要なら作業用ディレクトリを作成する

mkdir <ディレクトリ名>
cd <作成したディレクトリ名>

クローンを作成する

git clone https://github.com/ymmtd0x0b/sinatra-memoapp.git

アプリのあるフォルダへ移動する

cd ./sinatra_memoapp

アプリの動作に必要なGemをインストールする

bundle install

事前準備

アプリの起動前にデータベースとテーブルをローカルに準備する(初回のみ)

  1. 管理ユーザーでPostgreSQLにログイン
su - postgres
psql -U postgres
  1. メモアプリ用のデータベースを作成
CREATE DATABASE memo_app;
\c memo_app
  1. テーブルを作成
CREATE TABLE memo (
id SERIAL PRIMARY KEY NOT NULL,
title VARCHAR(50) NOT NULL,
content VARCHAR(300) NOT NULL);
  1. ユーザーを作成 アプリ側からデータベースを操作するためのユーザーを作成する
CREATE ROLE memoapp_user LOGIN PASSWORD '[password]';
  1. 作成したユーザーにアクセス権を付与( 今回はテーブルとシーケンスにアクセス権が必要 )
GRANT SELECT, UPDATE, INSERT, DELETE ON memo TO memoapp_user;
GRANT SELECT, UPDATE ON SEQUENCE memo_id_seq TO memoapp_user;
  1. 一度PostgreSQLを抜けるか、別途ターミナルを立ち上げてホームへ戻る

  2. テキストエディタにて.pgpassを開く(以下、例としてvimを使用)

cd ~
vim .pgpass
  1. .pgpassに以下をコピー&ペーストする
localhost:5432:memo_app:memoapp_user:[4.で指定したパスワード]
  1. .pgassファイルの権限を変更する 以下のようにすることで自分自身のアカウントでログインしてアプリを起動した場合のみログイン可能になるので、不正なログインを防止できる
chmod 600 .pgpass

起動

以下のコマンドでアプリを起動する

bundle exec ruby main.rb

http://localhost:4567 にアクセスするかブラウザのURLへ直接入力する

Image from Gyazo

sinatra-memoapp's People

Contributors

ymmtd0x0b avatar

Watchers

 avatar

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.