Last active
February 13, 2021 15:03
-
-
Save patriques82/5775813 to your computer and use it in GitHub Desktop.
Rails project setup
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Content | |
Installation | |
RubyGems | |
Gemsets | |
Updates | |
Configuration | |
Environment | |
Using .rvmrc file (Best if many projects) | |
Using different gemsets | |
Databases | |
A total example if everything works well | |
Gemfile example | |
Overview of project setup | |
Requires rvm, and ruby (if you have trouble with this maybe your Xcode is outdated and should be updated | |
"https://developer.apple.com/downloads/index.action" | |
This file is a summary of "http://railsapps.github.io/installing-rails.html" | |
Installation (on Mac) | |
1. Install command tools on XCode | |
2. Check that the gcc compiler was installed with command tools | |
$ gcc --version | |
3. Install homebrew (optional package manager for OS X for easy installations) | |
$ ruby -e "$(curl -fsSL https://raw.github.com/mxcl/homebrew/go)" | |
4. Install rvm (ruby version manager) with stable rails and ruby | |
$ \curl -L https://get.rvm.io | bash -s stable --rails --autolibs=enable | |
5. Check you have all the necessary requirements installed befor setting up the environment with rvm | |
$ rvm requirements | |
6. Relaunch terminal | |
7. Check rvm, ruby and rails was installed | |
$ rvm -v # should get 1.19.1 or higher | |
$ ruby -v # should get 2.0.0 or higher | |
$ rails -v # should get 3.2.13 or higher | |
RubyGems: | |
Ruby’s package management system is known as RubyGems, and packages or modules distributed using RubyGems are called “gems.” | |
The frontend script for RubyGems is gem, and it’s distributed with Ruby 1.9 just as irb and ri are. | |
$ gem install rails | |
to install rails for example, if you haven´t done it already when installing rvm | |
RubyGems module alters the require method itself so that it searches the set of installed gems before it searches the standard | |
library. When you load a gem with require (in either 1.8 or 1.9), it loads the most recent installed version of the gem you | |
specify. If you have more specific version requirements, you can use the gem method before calling require. | |
$ gem 'RedCloth', '> 2.0', '< 4.0' | |
activate RedCloth version 2.x or 3.x | |
$ require 'RedCloth' | |
and now load it | |
Gemsets: | |
$ rvm gemset list | |
to see all gems installed for current used gemset | |
$ rvm gemset use global | |
$ rvm gemset --help | |
help regarding gemset commands | |
$ rvm --help | |
help regarding rvm commands | |
Updates: | |
RVM creates a new completely separate gem directory for each version of ruby. RVM now provides a 'rubygems' CLI command which | |
allows you to change the rubygems version for the installed interpreter. In order to install the most recent RubyGems that | |
RVM knows about you can do: | |
$ rvm rubygems current | |
$ gem list # (Rubygems) | |
to see all gems in global gemset | |
You should have: | |
RubyGems 2.0.3 — newest RubyGems system gem (has among all gems rails) | |
Rake 10.0.4 — newest Rake gem | |
Bundler 1.3.5 — newest Bundler gem | |
Rubygems-Bundler 1.1.1 — newest version of Rubygems-Bundler | |
$ gem -v | |
and the update the package manager; RubyGems on system | |
$ gem update --system | |
$ gem update --system 1.8.24 | |
to freeze system to specific version | |
update other gems if necessary | |
$ gem update rake | |
$ gem update bundler | |
$ gem update rubygems-bundler | |
to update system gems | |
$ rvm upgrade --system | |
if problems arises with this, you can try | |
$ rvm reinstall 1.9.3 # or whatever version your currently using | |
if you can't install latest version of ruby check | |
$ rvm requirements | |
Configuration: | |
When installing gems, by default RubyGems generates two different kinds of documentation (called ri and rdoc), but many Ruby | |
and Rails developers find that the time to build them isn’t worth the benefit. (Many programmers rely on online documentation | |
instead of the native ri and rdoc documents.) To prevent the automatic generation of the documentation create a gem | |
configuration file in ~/ called .gemrc with these two lines | |
install: --no-rdoc --no-ri | |
update: --no-rdoc --no-ri | |
Environment: | |
rvm install certain version or implementation, for example: | |
$ rvm install 1.9.2 #(version) | |
$ rvm install ree #(ree is ruby enterprise edition) | |
a list of all implementation can be found | |
"https://github.com/cogitator/ruby-implementations/wiki/List-of-Ruby-implementations". | |
To see a list of different interpreters run | |
$ rvm list known | |
Using .rvmrc file (Best if many projects) | |
With rvm you can set up an environment for a certain project isolated from others that becomes default whenever you enter | |
the project. To do this you have to create a .rvmrc file in the root of your project like this. NOTE! You should include | |
this file in .gitignore. | |
$ cd path/to/project | |
$ touch .rvmrc | |
edit the created file and add the string "rvm version_or_implementation@name_of_gemset" on top of the file, for example | |
rvm jruby@my_project | |
Or | |
rvm 1.9.2@my_other_project | |
Whenever you enter one of the projects you have different environments. The commandpromt will ask you if you are sure and | |
if the contents are as you created. Answer 'yes' if they are. Then the commandpromt will say that the gemset is not created | |
and will suggest a gemset. To specify that gemset it asks for see below or above. Then when you enter the project folder | |
next time it wont ask if you are sure. Check out the isolated gemfile with | |
$ gem env gemdir | |
Using different gemsets | |
This is just for switching gemsets | |
$ rvm use 1.9.2 | |
to change to a certain version | |
$ rvm system | |
to change to system default. | |
This is just for momentary and changes to system default if you don´t tell rvm to use as default. | |
To create a special gemset for a project you can also for example use | |
$ rvm install ruby-1.9.3-p392 | |
$ rvm use [email protected] --create | |
This creates and starts using a gemset Rails3.2.12 with ruby version 1.9.3. This is the most stable version. After this you | |
can start installing gems and handling the project. | |
$ rvm use [email protected] --create --default | |
This is for using the same way as previous but now uses this as default | |
Note: if you want a certain implementation or version and don¨t want to handle this rvm use business you should go with the | |
.rvmrc file instead or default but this requires that your currently working on only one project. | |
If you’ve already created an application with the command rails new myapp, you can still create a project-specific gemset. | |
Here’s how to create a gemset for an application named “myapp” and create .ruby-version and .ruby-gemset files in the | |
application’s root directory: | |
$ rvm use ruby-2.0.0@myapp --ruby-version --create | |
You’ll need to install Rails and the gems listed in your Gemfile into the new gemset by running: | |
$ gem install rails | |
$ bundle install | |
Databases | |
$ rails new myapp --database= | |
to see all supported databases | |
$ rails new myapp --database=postgresql | |
to use postgresql and update the database.yaml file to use this instead of sqlite, which is used by default. Before doing | |
this check you have postgresql installed on the computer postgres | |
$ mdfind postgres | grep include | |
A total example if everything works well. | |
$ mkdir myRails32app | |
$ cd myRails32app | |
$ rvm install ruby-2.0.0 | |
$ rvm use [email protected] --create --default | |
$ rvm gemset list | |
$ gem install rails --version=3.2.13 | |
$ gem list | |
$ rails new . | |
Use the Rails Composer tool to build a full-featured Rails starter app. You’ll get a choice of starter applications with | |
basic features and popular gems. | |
$ rails new myapp -m https://raw.github.com/RailsApps/rails-composer/master/composer.rb | |
You can add the -T flags to skip Test::Unit if you are using RSpec for testing. | |
Gemfile example | |
source 'https://rubygems.org' | |
gem 'rails', '3.2.13' | |
group :development do | |
gem 'sqlite3', '1.3.5' | |
end | |
# Gems used only for assets and not required | |
# in production environments by default. | |
group :assets do | |
gem 'sass-rails', '3.2.5' | |
gem 'coffee-rails', '3.2.2' | |
gem 'uglifier', '1.2.3' | |
end | |
gem 'jquery-rails', '2.0.2' | |
This file example runs a stable version. After you have updated your gemfile the way you want it (there are other ways!) run | |
$ bundle update | |
$ bundle install | |
Installs all the gems specified in the gemfile that are project specific. You should be good to go.. | |
Overview of project setup | |
1. rails genarate scaffold <Models> <attributes> | |
2. create configuration/locales/se.yml file (for language) | |
activerecord: | |
attributes: | |
<model>: | |
<attribute, such as name> | |
errors: | |
models: | |
<model>: | |
<attribute, such as name> | |
<message>: "Du gjorde fel!" | |
For more information about gems and using them visit "http://railsapps.github.io/" | |
For more information about git workflow "http://railsapps.github.io/rails-git.html" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment