ruby-on-rails-4
#ruby-on-rails-4
1
1: ruby-on-rails-4
2
2
Examples
2
2
Rails
3
UbuntuRuby On Rails16.10 Yakkety Yak
3
Ruby
4
Rails
5
PostgreSQL
6
2:
7
Examples
7
7
8
You can share this PDF with anyone you feel could benefit from it, downloaded the latest version
from:
ruby-on-rails-4
It is an unofficial and free ruby-on-rails-4 ebook created for educational purposes. All the content is
extracted from
Stack Overflow Documentation
, which is written by many hardworking individuals at
Stack Overflow. It is neither affiliated with Stack Overflow nor official ruby-on-rails-4.
The content is released under Creative Commons BY-SA, and the list of contributors to each
chapter are provided in the credits section at the end of this book. Images may be copyright of
their respective owners unless otherwise specified. All trademarks and registered trademarks are
the property of their respective company owners.
Use the content presented in this book at your own risk; it is not guaranteed to be correct nor
accurate, please send your feedback and corrections to
[email protected]
1: ruby-on-rails-4
をいめる
このセクションでは、
ruby-on-rails-4
のと、なぜがそれをいたいのかをします。
また、
Ruby-on-rails-4
のきなテーマについてもし、するトピックにリンクするがあります。
ruby-on-rails-4
のドキュメントはしくなっているので、それらのトピックのバージョンをするがありま
す。
Examples
インストールまたはセットアップ
Ubuntu 16.04 Xenial Xerus
の
Ruby On Rails
をセットアップする
すべてのコマンドは
Linux
でするがありますホットキー
Ctrl + Alt + T
では、ローカルマシンに
Ruby
をインストールするがあります。のステップは、
Ruby
のいくつか
のをインストールすることです。
sudo apt-get update
sudo apt-get install git-core curl zlib1g-dev build-essential libssl-dev libreadline-dev libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt1-dev libcurl4-openssl-dev python-software-properties libffi-dev
Ruby
は、の3つののいずれかをしてインストールできます。これらのにはおいにするものがあり
ますので、あなたにとってもいものをんでください。
の
rbenv
インストールする
cd
git clone https://github.com/rbenv/rbenv.git ~/.rbenv echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc echo 'eval "$(rbenv init -)"' >> ~/.bashrc
exec $SHELL
git clone https://github.com/rbenv/ruby-build.git ~/.rbenv/plugins/ruby-build echo 'export PATH="$HOME/.rbenv/plugins/ruby-build/bin:$PATH"' >> ~/.bashrc exec $SHELL
rbenv install 2.3.3 rbenv global 2.3.3 ruby -v
のステップは
Bundler
をインストールすることです
gem install bundler
sudo apt-get install libgdbm-dev libncurses5-dev automake libtool bison libffi-dev
gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 curl -sSL https://get.rvm.io | bash -s stable
source ~/.rvm/scripts/rvm rvm install 2.3.3
rvm use 2.3.3 --default ruby -v
のステップは
Bundler
をインストールすることです
gem install bundler
3
のソースからのインストール
cd wget http://ftp.ruby-lang.org/pub/ruby/2.3/ruby-2.3.3.tar.gz tar -xzvf ruby-2.3.3.tar.gz cd ruby-2.3.3/ ./configure makesudo make install ruby -v
のステップは
Bundler
をインストールすることです
gem install bundler
Rails
のインストール
Rails
にはくのがしていますので、
NodeJS
のような
JavaScript
をインストールするがあります。こ
れにより、よりなプロダクションをするために、
JavaScript
をみわせ、した
Coffee
スクリプトと
Asset Pipeline
in Rails
をできます。
curl -sL https://deb.nodesource.com/setup_4.x | sudo -E bash - sudo apt-get install -y nodejs
すぐ
Rails 4.2.6をインストールしてください
gem install rails -v 4.2.6 (you may set a specific version of rails)
rbenv
をしているは、のコマンドをします。
rbenv rehash
に、
rails -vをして、すべてがしくインストールされていることをします。それはあなたのレー
ルのバージョンをするがあります。
# Rails 4.2.6UbuntuでのRuby On Railsのセットアップ16.10 Yakkety Yak
これには
30
かかります。
Ruby on Rails
を
Ubuntu 16.10 Yakkety Yak
にするです。
Ctrl
+
Alt+
Tをしてをきます。
Ruby
のインストール
のステップは、
Ruby
のをインストールすることです。
sudo apt-get update
sudo apt-get install git-core curl zlib1g-dev build-essential libssl-dev libreadline-dev libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt1-dev libcurl4-openssl-dev python-software-properties libffi-dev nodejs
Ruby
バージョン2.4.0をします。 3つののいずれかをして
Ruby
をインストールします。それぞれ
がのをっていますが、ほとんどのは
rbenv
をんでいますが、
rvm
にしていればそれをおしください
。
rbenv
ユーザーは、
bundlerをインストールしたに
rbenv rehashをするがあります。
rbenvを
rbenvインストールする
cd
git clone https://github.com/rbenv/rbenv.git ~/.rbenv echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc echo 'eval "$(rbenv init -)"' >> ~/.bashrc
exec $SHELL
git clone https://github.com/rbenv/ruby-build.git ~/.rbenv/plugins/ruby-build echo 'export PATH="$HOME/.rbenv/plugins/ruby-build/bin:$PATH"' >> ~/.bashrc exec $SHELL
rbenv install 2.4.0 rbenv global 2.4.0 ruby -v
に、
Bundler
をインストールします。
gem install bundler
bundler
をインストールし
rbenv rehashしてください。
rvmを
rvmインストールする
sudo apt-get install libgdbm-dev libncurses5-dev automake libtool bison libffi-dev
gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 curl -sSL https://get.rvm.io | bash -s stable
source ~/.rvm/scripts/rvm rvm install 2.4.0
ruby -v
に、
Bundler
をインストールします。
gem install bundler
ソースによるインストール
cd wget http://ftp.ruby-lang.org/pub/ruby/2.4/ruby-2.4.0.tar.gz tar -xzvf ruby-2.4.0.tar.gz cd ruby-2.4.0/ ./configure makesudo make install ruby -v
に、
Bundler
をインストールします。
gem install bundler
Rails
のインストール
、Railsにはにくのがあるため、
NodeJS
のような
JavaScript
ランタイムをインストールするがあり
ます。これにより、よりいをするために、
JavaScript
をしたり、したりする、
Coffee-script
と
Asset Pipeline
in Rails
をできます。
リポジトリをして
NodeJS
をインストールします。
curl -sL https://deb.nodesource.com/setup_4.x | sudo -E bash - sudo apt-get install -y nodejs
Rails 4.2.7
インストールし
Rails 4.2.7。
gem install rails -v 4.2.7.1rbenv
をしているは、のコマンドをして、
rails
のファイルをにします。
rbenv rehash
Rails
がインストールされました
rails -vをして、
rails -vしくインストールされていることをし
ます。
rails -v # Rails 4.2.7.1
らかのでのがられたは、がしくされていないがあります。
PostgreSQL
をする
Rails
には、デフォルトのデータベースとして
sqlite3
がしています。ディスクにシンプルファイル
としてされているため、したくないがあります。おそらく、
MySQL
や
PostgreSQL
のようにより
なものがになるでしょう。
のドキュメントがたくさんあるので、あなたはもっとにえるものをぶことができます。
sudo sh -c "echo 'deb http://apt.postgresql.org/pub/repos/apt/ xenial-pgdg main' > /etc/apt/sources.list.d/pgdg.list"
wget --quiet -O - http://apt.postgresql.org/pub/repos/apt/ACCC4CF8.asc | sudo apt-key add - sudo apt-get update
sudo apt-get install postgresql-common sudo apt-get install postgresql-9.5 libpq-dev
PostgreSQL
のインストールではユーザがされないので、データベースをするをつユーザをするに
は、のにうがあります。あなたのユーザーで
Hizqeelをしてください。
sudo -u postgres createuser hizqeel -s
# If you would like to set a password for the user, you can do the following sudo -u postgres psql
postgres=# \password hizqeel
オンラインでruby-on-rails-4をいめるをむ
https://riptutorial.com/ja/ruby-on-rails-4/topic/4014/ruby-on-rails-4
をいめる
2:
いパラメータの
Examples
なパラメータとはですか
edgeapi
がするように、エンドユーザーりてからをするためのインターフェイスをします。これに
より、アクションコントローラのパラメータは、ホワイトリストにされるまでアクティブモデル
のりてですることをされます。
さらに、にじてパラメータをマーキングし、あらかじめされた
/
のれをって、400のいにわらせる
ことができます。
PeopleControllerファイルとコメントをして、なパラメータのをしてください。
class PeopleController < ActionController::Base
# Using "Person.create(params[:person])" would raise an
# ActiveModel::ForbiddenAttributesError exception because it'd # be using mass assignment without an explicit permit step. # This is the recommended form:
def create
Person.create(person_params) end
# This will pass with flying colors as long as there's a person key in the # parameters, otherwise it'll raise an ActionController::MissingParameter # exception, which will get caught by ActionController::Base and turned # into a 400 Bad Request reply.
def update
redirect_to current_account.people.find(params[:id]).tap { |person| person.update!(person_params)
} end
private
# Using a private method to encapsulate the permissible parameters is # just a good pattern since you'll be able to reuse the same permit # list between create and update. Also, you can specialize this method # with per-user checking of permissible attributes.
def person_params params.require(:person).permit(:name, :age) end end