This tutorial is about setting up environment for RubyOnRails on Ubuntu 14.04.
First of all, update & upgrade your system:
sudo apt-get update
^
sudo apt-get upgrade
^
Install git
and curl
:
sudo apt-get install curl
^
sudo apt-get install git-core
^
Configure git
:
git config --global user.name "Your Name"
^
git config --global user.email email@example.com
^
Install RVM
:
curl -sSL https://get.rvm.io | bash -s stable
^
source ~/.rvm/scripts/rvm
^
Test RVM
installation correctness:
type rv...
All examples here for deploy RoR application with unicorn, staging machine (where we deploys) available via ssh by ssh_key.
Deploy via remote_cache:
require 'rvm/capistrano'
require 'bundler/capistrano'
set :application, '_proj_'
set :rails_env, 'production'
set :domain, '_user@your_deploy_domain_'
set :deploy_to, "_path_to_#{application}"
set :use_sudo, false
set :unicorn_conf, "#{deploy_to}/current/config/unicorn.rb"
set :unicorn_pid, "#{deploy_to}/shared/pids/u...
Add repository and install Postgresql:
^
sudo sh -c "echo 'deb http://apt.postgresql.org/pub/repos/apt/ precise-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.3 libpq-dev
^
Then make yourself a Postgresql superuser:
sudo su postgres
^
createuser your_system_login
^
psql
^
ALTER ROLE your_system_login WITH SUPERUS...
Just mark needed describes
and its
as ddiscribe
and iit
, and next time you run tests only ddiscribes and iits will be executed. In Jasmine version >= 2.0 use fit
and fdescribe
respectively.
Add in Gemfile:
group :development, :test do
gem 'rspec-rails'
gem 'spork-rails'
end
group :test do
gem 'capybara'
gem 'database_cleaner'
gem 'email_spec'
gem 'poltergeist'
gem 'launchy'
gem 'selenium-webdriver'
end
Run bundle install
Ensure your spec_helper.rb
looks similar with this:
require 'rubygems'
require 'spork'
#uncomment the following line to use spork with the debugger
# require 'spork/ext/ruby-debug'
Spork.prefork do
# Loading more in this block will cause your tests to ...
Visit PhantomJS site, go to download page and copy link address for Linux, in our case this is https://phantomjs.googlecode.com/files/phantomjs-1.9.2-linux-x86_64.tar.bz2
Then go to console and run following commands:
sudo apt-get install libfontconfig libfontconfig-dev libfreetype6-dev
^
wget https://phantomjs.googlecode.com/files/phantomjs-1.9.2-linux-x86_64.tar.bz2
^
sudo mv phantomjs-1.9.2-linux-x86_64.tar.bz2 /opt
^
cd /opt
^
tar -xvf phantomjs-1.9.2-linux-x86_64.tar.bz2
^
ln -s /opt/phantomjs-1.9.2-linux-x8...
NVM provides you more convenient way to manage and set up your Javascript(Node.js) environment.
First install NVM, note git
must be installed on your sistem:
^
git clone https://github.com/creationix/nvm.git ~/.nvm && cd ~/.nvm && git checkout git describe --abbrev=0 --tags
^
To activate nvm, you need to source it from your shell:
^
cd # go to home folder
^
source ~/.nvm/nvm.sh
^
If you want to see what versions of Node.js are available to install:
^
nvm ls-remote
^
To install Node.js v0.11.14 just run:
^
nvm install...
If you don't have ssh key, open terminal and run following commands:
cd ~/.ssh
^
ssh-keygen -t rsa -C "your_email@example.com"
When you have ssh key, just copy public part to clipboard:
xclip -sel clip < ~/.ssh/id_rsa.pub
To install xclip run:
sudo apt-get install xclip
Then add to GitHub or GitLab keys in profile settings
Suppose you want to create node with name text
, but this method already present in Nokogiri::XML::Builder. The solution is to add underscore after node name:
Nokogiri::XML::Builder.new do |xml|
xml.text_ 'something' # this should create node with name 'text'
end
Assume your database.yml file looks like this:
{: .yaml}
development:
adapter: postgresql
host: localhost
encoding: unicode
database: proj_development
pool: 5
username: proj
password:
template: template0
test:
adapter: postgresql
host: localhost
encoding: unicode
database: proj_test
pool: 5
username: proj
password:
template: template0
production:
adapter: postgresql
host: localhost
encoding:...
To install nginx with txid module
install nginx-full package:
sudo apt-get install nginx-full
download last nginx source:
wget http://nginx.org/download/nginx-1.9.9.tar.gz
examine what flags and modules your current nginx installed with:
nginx -V
you will see something like
nginx version: nginx/1.6.2 (Ubuntu)
TLS SNI support enabled
configure arguments: --with-cc-opt='-g -O2 -fPIE -fstack-protector-strong -Wformat -Werror=format-security -D_FORTIFY_SOURCE=2' --with-l...
For that purpose, just use these command:
bundle install --without production
Suppose we have some model and we want to localize it, first of all we need to now i18n_key for that model. Open rails console rails c
, and run:
OurModelName.model_name.i18n_key
For example let's do that for model, defined in public_activity gem:
PublicActivity::Activity.model_name.i18n_key
#=> :"public_activity/activity"
Now, we cat easily localize it, by adding this in .yaml file:
activerecord:
models:
public_activity/activity: 'Our localized model name'
In the same way we can locali...
require 'rake'
rake = Rake.application
rake.init
# you can import addition *.rake files
# app.add_import 'some/other/file.rake'
rake.load_rakefile
rake['db:test:prepare'].invoke()
In case you want to organize your features in sub folders, you must tell Cucumber where to find step definitions for them, for that reason use --require
flag. For example, your features located in folder features/awesome_staff/*.*
, to run them do the following:
cucumber --require features features/awesome_staff
And Cucumber takes step definitions from folder features/step_definitions
class CreateFakes < ActiveRecord::Migration
def change
create_table :fakes do |t|
t.decimal :float_value, :precision => 4, :scale => 3
end
end
end
This will allow you to have 3 digits after the decimal point and 4 digits max.
If some of your scripts don't work with turbolinks, you should do the following:
ready = ->
#your code here
$(document).ready(ready)
$(document).on('page:load', ready)
For css rules only for Firefox use this container:
@-moz-document url-prefix() {
#some_id{
height: auto;
}
}
Install capistrano:
add to Gemfile
group :development do
gem 'capistrano'
gem 'rvm-capistrano'
end
Then cd to project root folder and run:
bundle install
capify .
setup your config/deploy.rb
file, here some useful examples
cap deploy:setup #before first deploy
cap deploy:check #before first deploy
cap deploy:cold # for first deploy
cap deploy #for subsequent deploys
To get parent of Capybara's node do the following:
node = page.find '#selector'
parent = node.find(:xpath, '..')
parent_of_parent = node.find(:xpath, '../..')
Check conditions example:
<!-- run command -->
<target name="t_name">
<exec executable="command" failonerror="true" outputproperty="exec.out" errorproperty="exec.err" resultproperty="exec.rc" >
<arg value="arg"/>
</exec>
</target>
<!-- check conditions -->
<target name="checkresult">
<condition property="errors">
<not>
<equals arg1="${exec.err}" arg2="0" />
</not>
</condition>
<echo message="errors: ${errors}"/>
</target>
...
To do this you should type:
ls --full-time -t
The output will be similar to this:
drwxr-xr-x 2 konjoot konjoot 4096 2016-02-06 17:28:20.915296664 +0300 temp
drwxr-xr-x 40 konjoot konjoot 20480 2015-12-22 22:13:37.444222190 +0300 Books
-rw-rw-r-- 1 konjoot konjoot 186815 2015-05-26 21:52:29.326181000 +0300 ava.png
-rwx------ 1 konjoot konjoot 79011 2015-05-19 10:48:01.000000000 +0300 screen.png
drwxr-xr-x 3 konjoot konjoot 4096 2015-03-27 02:24:04.832060055 +0300 docs
drwxr-xr-x 2 konjoot konjoot 4096 2014-08-04 03...
First install python-software-properties
:
sudo apt-get install python-software-properties
Next, remove openjdk
package if installed:
sudo apt-get remove openjdk*
Now, add java repository by webupd8team:
sudo add-apt-repository ppa:webupd8team/java
And update your system:
sudo apt-get update
For installing Oracle Java 7 run:
sudo apt-get install oracle-java7-installer
For Oracle Java 6 run:
sudo apt-get install oracle-java6-installer
For Oracle Java 8 run:
sudo apt-get install oracl...