Utilisation Rails

De Wiki Arthion

Installation sur windows

<poem> installer ruby http://rubyforge.org/frs/?group_id=167 Rubygem est intégré par défaut, pas besoin de l'installer en plus<ref>http://railsforum.com/viewtopic.php?id=40680</ref> installer rails : gem install rails

Se posera ensuite le probleme de sqlite : il manque une dll a télécharger ici : http://www.sqlite.org/sqlitedll-3_6_23_1.zip&usg=AFQjCNHwBH26R58himuhS3o9hBMb8MGIdA<ref>http://groups.google.com/group/sqlite3-ruby/msg/14900c6f29f9a825</ref> puis mettre le dll dans le ruby/bin

cela permet de lancer la commande rails server sans probleme

</poem>

Installation sur ubuntu

Méthode obsolete et non fiable

<poem> apt-get install ruby apt-get install ruby1.8-dev<ref>http://mentalized.net/journal/2006/01/24/no_such_file_to_load_mkmf/</ref> apt-get install libsqlite3-dev<ref>http://www.jsiegel.com/2008/10/fixed-ubuntu-sudo-gem-install-sqlite3.html</ref> apt-get install libopenssl-ruby1.8<ref>http://morecode.wordpress.com/2007/01/16/capistrano-error-no-such-file-to-load-openssl-ruby-on-rails/</ref> bundle install gem install sqlite3-ruby </poem>

Methode fonctionnelle

Prérequis minimums: Git, curl, sqlite3 doivent etre installés

sudo apt-get install git curl build-essential libxslt-dev libxml2-dev libsqlite3-0 libsqlite3-dev sqlite3 libssl-dev libreadline5 libreadline5-dev


Prérequis au fonctionnement de Heroku:

apt-get install bison openssl zlib1g zlib1g-dev 

Installation de RVM

bash < <(curl -s https://rvm.beginrescueend.com/install/rvm) <ref>https://rvm.beginrescueend.com/rvm/install/</ref>
echo '-s "$HOME/.rvm/scripts/rvm" && . "$HOME/.rvm/scripts/rvm" # Load RVM function' >> ~/.bash_profile

Une fois rvm installé, installer ruby 1.9.2 rvm get head rvm reload rvm install 1.9.2

Créer son gemset préféré

rvm --create use 1.9.2@rails

Mettre sa version et son gemset en défaut

rvm --default use 1.9.2@rails

Mettre a jour son rubygem au cas où

gem update

supprimer la création des docs lors de l'import de gemmes (ligne à ajouter dans ~/.gemrc)

gem: --no-ri --no-rdoc

Installer rails

gem install rails

Une fois son projet créé avec rails new nomappli, créer son bundle de gemmes avec

bundle install

Installation Heroku

gem install heroku
heroku keys:add
heroku create
git push heroku master

Tests en continu

gem install ZenTest
gem install redgree

sudo apt-get install libnotify-bin

Utilisation

<poem> rails script/generate ou rails g rails g model rails g model Story name:string link:string rake -T rake db:migrate rake db:migrate VERSION = rails console

Manipulation de données: (en supposant le modele Story généré) s=Story.new s.name="truc" s.link= 'machine' s.save s.id Story.count en plus court Story.create(

 :name => 'SitePoint Forums', 
 :link => 'http://www.sitepoint.com/forums/') 

Story.find(2) Story.find(:all) Story.find(:first,:order => 'id DESC') s=Story.find_by_name('truc') s.name='machine' s.update_attribute :name, 'Pouet' s.destroy

<% Commande ruby %> silentieux <%= commande ruby %> renvoie


Formulaires : <% form_for @story do |f| %>

<%= f.text_field :name %>
<%= f.text_field :link %>

<% end %> methodes possibles : text_field, password_field, check_box, text_area

<%= submit_tag %>


Story.find(:all).each do |s| s.user_id = 1 s.save end



Installer un plugin hebergé par git pour rails : installer git : sudo apt-get install git-core puis rails plugin install adresse_du_pluign.git

il s'installe dans le repertoire /vendor/plugin de l'application </poem>


Lancement de l'environnement de dev

<poem> rails server spork autotest </poem> <references/>

Notes

<references/>