Utilisation Rails

De Wiki Arthion
Version datée du 15 septembre 2010 à 12:56 par Maelli (discussion | contributions) (Utilisation)
(diff) ← Version précédente | Version actuelle (diff) | Version suivante → (diff)

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

<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>


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>

Notes

<references/>