YOU ARE DOWNLOADING DOCUMENT

Please tick the box to continue:

Transcript
  • 1. Ruby on Rails

2. Ruby on RailsPourquoi a dchire ? 3. whoamiSimon COURTOIS CTO chez SelectraGithug: simoncTwitter: @happyno 4. MV C 5. M odel View C ontroller 6. OR M 7. Object R elational Mapping 8. Active Recordarticlesidtitle body1 hello world This is a body # app/models/article.rb class Article < ActiveRecord::Base end article = Article.first article.title #=> "hello world" 9. Active Recordarticlesidtitle body published1 hello world This is a body 12 other art.Not published0 articles = Article.where(published: 1) articles.count #=> 1 10. ConventionsConguration 11. Active Recordarticles# app/models/article.rbidtitlebody author_id class Article < ActiveRec...belongs_to :author1 ......1 end# app/models/author.rbclass Author < ActiveRec... authorshas_many :articlesend id namearticle = Article.first 1John Doearticle.author.name#=> John Doe 12. Active RecordMySQLPostgreSQLSQLite... 13. Routing# app/controller/hello_controller.rbclass HelloController < ApplicationControllerdef index@name = params[:name]endend http://example.com/hello/John# config/routes.rbget "hello/:name" => "hello#index" action du contrleur URLcontrleurverbe HTTP paramtre 14. Vues# app/controller/hello_controller.rbclass HelloController < ApplicationControllerdef index@name = params[:name]endend# app/views/hello/index.html.erbBonjour Conventions ! 15. Helpers# app/controller/articles_controller.rbclass ArticlesController < ApplicationControllerdef new@article = Article.newendend Title


Body


Create Article 16. Railties$ rake routesGET /hello/:name { :controller => "hello", :action => "index" }$ rails serverLance un serveur web sur http://localhost:3000/$ rails consoleLance une console avec le contexte de lapplication>> Article.first.title#=> "hello world" 17. Gnrateurs$ rails generate model author name:stringinvoke active_recordcreate db/migrate/20120108151543_create_authors.rbcreate app/models/author.rb instructions de cration de la table authorsmodle Author 18. Gnrateurs$ rails g scaffold author name:stringcreate db/migrate/20120108152723_create_authors.rbcreate app/models/author.rb modlerouteresources :authorsroutescreate app/controllers/authors_controller.rb contrleurcreate app/views/authors/index.html.erbcreate app/views/authors/edit.html.erbcreate app/views/authors/show.html.erbcreate app/views/authors/new.html.erb vuescreate app/views/authors/_form.html.erbcreate public/stylesheets/scaffold.css CSS par dfaut 19. Gnrateurs # config/routes.rb resources :authors authors GET /authors{ action: index controller: authors } authorGET /authors/:id{ action: showcontroller: authors } new_authorGET /authors/new{ action: new controller: authors } POST /authors { action: createcontroller: authors } edit_author GET /authors/:id/edit { action: editcontroller: authors } PUT /authors/:id{ action: updatecontroller: authors } DELETE /authors/:id { action: destroy controller: authors } 20. Gnrateurs 21. Gnrateurs 22. Gnrateurs 23. Gnrateurs 24. Gnrateurs 25. Gnrateurs 26. Gnrateurs 27. Gnrateurs 28. Les petits plus dActiveSupport1.kilobytes! #=> 10243.days.ago!! #=> Sat, 04 Feb 2012 17:45:42 CET +01:00"hh test".parameterize! #=> "hehe-test"article.pluralize! ! ! #=> "articles" ! 29. ExtensibilitGrce aux Gems 30. Vues et formulaires



slim + simple_form = simple_form_for @article do |f|= f.input :title= f.input :body= f.submit 31. Et tant dautresMongoidPagination MongoDBKaminariCarierwave Systme dadministrationUpload de fichiersActive Admin 32. Qui utilise Rails ? TwitterGithub BasecampPages Jaunes US Groupon Shopifyhttp://rubyonrails.org/applications 33. Ressourcesrubyonrails.org Site officieltutorials.jumpstartlab.com/topics Tutorial trs completrailsforzombies.org Tutorial interactifrailstutorial.org/bookLivre gratuit en ligne#rubyonrails.fr Channel IRC franais 34. Questions ? 35. Merci !


Related Documents