Ruby on Rails Guide – P1                                      Brady Chenghttp://bradyisstudying.blogspot.tw/
AgendaPrerequisiteFirst App
PrerequisiteWhat is Ruby?  A programming languageWhat is Rails?  A web application framework programmed by Ruby
Prerequisite           MVC              Model-View-Controller              Refer to this slide for other details          ...
PrerequisiteREST  CRUD       REST     Note  Create     Post     New data  Read       Get      Read data  Update     Put   ...
PrerequisiteInstallation  Windows base    http://railsinstaller.org/  Trouble shooting    ERROR: Error installing json: Th...
PrerequisiteCreate a new project  rails new your_project_nameStart the created project  cd project_name  bundle install  r...
PrerequisiteProject organization  /app    Organize your models, views, and controllers  /config    Configs such as databas...
PrerequisiteProject organization  /doc     Docs generated by RubyDoc framework  /lib     Libs for your applications  /log ...
PrerequisiteProject organization  /script    Some scripts for your applications  /test    Some tests written by you or by ...
PrerequisiteSnapshot
First AppWe can use the following command to new acontroller and related files      rails generate GENERATOR ARGGenerator ...
First AppSnapshot of the responses
First App           Testing your http://127.0.0.1:3000/greeting           Edit your config/routes.rb                      ...
First AppAfter updating the routes.rbAdd an index function in your controllerdef index   render :text=>”Hello Ruby world!”...
First AppAforementioned approach is somehow dirty  We need to follow the MVC rulesUpdate the index function in controller ...
First AppWorth to mention what erb file isERB file = html code + ruby code  Ruby code will be surrounded by <%...%> or <%=...
First AppWorth to mention the Request scopeRequest scope  Each http request will get a copy of the controller    Pros : th...
Upcoming SlideShare
Loading in …5
×

RoR guide_p1

476 views
440 views

Published on

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
476
On SlideShare
0
From Embeds
0
Number of Embeds
134
Actions
Shares
0
Downloads
4
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

RoR guide_p1

  1. 1. Ruby on Rails Guide – P1 Brady Chenghttp://bradyisstudying.blogspot.tw/
  2. 2. AgendaPrerequisiteFirst App
  3. 3. PrerequisiteWhat is Ruby? A programming languageWhat is Rails? A web application framework programmed by Ruby
  4. 4. Prerequisite MVC Model-View-Controller Refer to this slide for other details http://www.slideshare.net/jaceju/mvc-8761203Img src: http://www.ils.unc.edu/~uskala/MVC.htm
  5. 5. PrerequisiteREST CRUD REST Note Create Post New data Read Get Read data Update Put Update data Delete Delete Delete data
  6. 6. PrerequisiteInstallation Windows base http://railsinstaller.org/ Trouble shooting ERROR: Error installing json: The json native gem requires installed build tools. http://stackoverflow.com/questions/8100891/the-json- native-gem-requires-installed-build-tools
  7. 7. PrerequisiteCreate a new project rails new your_project_nameStart the created project cd project_name bundle install rails server Check http://localhost:3000 or http://127.0.0.1:3000
  8. 8. PrerequisiteProject organization /app Organize your models, views, and controllers /config Configs such as database config (database.yml), rails environmental config (environment.rb)…etc /db Manage your database
  9. 9. PrerequisiteProject organization /doc Docs generated by RubyDoc framework /lib Libs for your applications /log Error log such as “server.log”, “development.log”…etc /public Some html files for your applications
  10. 10. PrerequisiteProject organization /script Some scripts for your applications /test Some tests written by you or by rails such as unit test, fixture tests…etc. /tmp Temp files /vendor Third party libs
  11. 11. PrerequisiteSnapshot
  12. 12. First AppWe can use the following command to new acontroller and related files rails generate GENERATOR ARGGenerator can be assets, controller, helper…etcARG here is the file name
  13. 13. First AppSnapshot of the responses
  14. 14. First App Testing your http://127.0.0.1:3000/greeting Edit your config/routes.rb resources :greetinghttp://stackoverflow.com/questions/11696695/routing-error-ruby-on-rails
  15. 15. First AppAfter updating the routes.rbAdd an index function in your controllerdef index render :text=>”Hello Ruby world!”end
  16. 16. First AppAforementioned approach is somehow dirty We need to follow the MVC rulesUpdate the index function in controller def index @welcome_msg = "Hello RoR world“ endUpdate view/index.html/erb <%= @welcome_msg %>
  17. 17. First AppWorth to mention what erb file isERB file = html code + ruby code Ruby code will be surrounded by <%...%> or <%=…%> <% code here %> : pure logic, nothing display to screen <%= code here %> : display something to screen
  18. 18. First AppWorth to mention the Request scopeRequest scope Each http request will get a copy of the controller Pros : thread safe Cons: hard to share data between different requests Solution: use sessions

×