Подготовка окружения для проекта Ruby on Rails
rbenv
# yum install -y \
which \
tar \
curl \
openssl-devel \
git \
gcc
# git config --global color.ui true
1) Создал пользователя developer.
# useradd \
-d /home/developer \
-m developer
# passwd developer
# mkdir /rails_projects
# chown -R developer /rails_projects/
# su - developer
=======================
$ git clone git://github.com/sstephenson/rbenv.git .rbenv
$ echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc
$ echo 'eval "$(rbenv init -)"' >> ~/.bashrc
$ exec $SHELL
$ git clone git://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build
$ echo 'export PATH="$HOME/.rbenv/plugins/ruby-build/bin:$PATH"' >> ~/.bashrc
$ exec $SHELL
$ rbenv install --list
$ rbenv install 2.1.4
$ rbenv versions
* 2.1.3 (set by /home/developer/.rbenv/version)
2.1.4
$ rbenv global 2.1.4
$ ruby -v
https://gorails.com/setup/ubuntu/14.10
============================================================
============================================================
RubyGems
$ gem -v
2.2.2
$ gem list
$ gem update --system
============================================================
Rails
$ echo "gem: --no-ri --no-rdoc" > ~/.gemrc
$ gem install bundler
$ rbenv rehash
$ bundle -v
Bundler version 1.7.4
$ gem install rails --no-ri --no-rdoc
$ rbenv rehash
$ rails -v
==========================================================
MySQL
# yum install -y mysql-devel mysql mysql-server
$ gem install mysql2
-----
Sqlite
-- В Centos 6.5
# yum install -y sqlite-devel
-- В Ubuntu 14.04
# apt-get install libsqlite3-dev
==========================================================
CREATING a PROJECT
$ cd /rails_projects
// mysql
$ rails new myApp1 -d mysql
// sqlite
$ rails new myApp1 -d sqlite3
$ cd myApp1/
$ vi Gemfile
Оставили только rails и mysql2 / sqlite3
==========================================================
rails console
# yum install readline-devel
в GemFIle добавляю
gem 'rb-readline'
$ bundle install
==========================================================
$ vi ./config/database.yml
Указываем логин и пароль для подключения к базе.
Комментируем название базы если имеется.
database: #myApp1_development
============================================================
WebServer (WEBrick)
$ rails server
http://192.168.1.21:3000/
============================================================
============================================================
Generatin a Controller and View
$ rails generate controller demo index
$ vi app/controllers/demo_controller.rb
class DemoController < ApplicationController
layout false
def index
end
end
http://192.168.1.21:3000/demo/index