Your SlideShare is downloading. ×
0
Ruby on Rails Pei-Ying Wang
Ruby on Rails Pei-Ying Wang
Ruby on Rails Pei-Ying Wang
Ruby on Rails Pei-Ying Wang
Ruby on Rails Pei-Ying Wang
Ruby on Rails Pei-Ying Wang
Ruby on Rails Pei-Ying Wang
Ruby on Rails Pei-Ying Wang
Ruby on Rails Pei-Ying Wang
Ruby on Rails Pei-Ying Wang
Ruby on Rails Pei-Ying Wang
Ruby on Rails Pei-Ying Wang
Ruby on Rails Pei-Ying Wang
Ruby on Rails Pei-Ying Wang
Ruby on Rails Pei-Ying Wang
Ruby on Rails Pei-Ying Wang
Ruby on Rails Pei-Ying Wang
Ruby on Rails Pei-Ying Wang
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Ruby on Rails Pei-Ying Wang

802

Published on

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

  • Be the first to like this

No Downloads
Views
Total Views
802
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
10
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. Ruby on Rails Pei-Ying Wang peiatw@sfsu.edu <ul><li>Overview </li></ul><ul><ul><li>What is Ruby on Rails? </li></ul></ul><ul><ul><li>Rails frameworks (components) </li></ul></ul><ul><ul><li>Example: simple web application </li></ul></ul><ul><ul><li>Pros and Cons </li></ul></ul>
  • 2. What is Ruby on Rails? <ul><li>Ruby  Ruby on Rails </li></ul><ul><ul><li>An open source, interpreted scripting language </li></ul></ul><ul><ul><li>Created by Yukihiro Matsumoto in the mid-1990s </li></ul></ul><ul><li>Ruby on Rails, ROR or Rails </li></ul><ul><ul><li>An full-stack, open source web application framework written in Ruby </li></ul></ul><ul><ul><li>Designed for writing database-oriented real-world Web application quickly and easily </li></ul></ul><ul><ul><li>Created by David Heinemeier Hansson </li></ul></ul>
  • 3. What is Ruby on Rails?(2) <ul><li>Very short history </li></ul><ul><ul><li>Extracted from Basecamp(a project-management tool by 37Signals) </li></ul></ul><ul><ul><li>First released : July 2004 </li></ul></ul><ul><ul><li>Latest release: April 2006(Version 1.1.2) </li></ul></ul><ul><li>Principles(DRY- D on’t R epeat Y ourself) </li></ul><ul><ul><li>Less software </li></ul></ul><ul><ul><li>Convention over Configuration </li></ul></ul>
  • 4. Rails Frameworks(components)
  • 5. Example: a simple web application After starting MySQL and Web server, Create a new web application called cookbook2: &gt; Rails cookbook2
  • 6. Example: a simple web application(2) class MyTestController &lt; ApplicationController end &gt; ruby scriptgenerate controller MyTest To make a simple Hello World application:
  • 7. Example: a simple web application(3) To make a simple Hello World application(2): class MyTestController &lt; ApplicationController def index render_text &amp;quot;Hello World&amp;quot; end end http:// localhost :3000/My_Test/index http://localhost:3000//My_Test http://localhost:3000/MyTest
  • 8. Example: a simple web application(4) <ul><li>Online Recipe </li></ul><ul><ul><li>First, create an database called cookbook2 and a table called recipes </li></ul></ul>
  • 9. Example: a simple web application(5) &gt; ruby scriptgenerate model Recipe
  • 10. Example: a simple web application(6) &gt; ruby scriptgenerate controller Recipe Magic happens by simply adding this line to recipe_controller.rb !  Open browser and go to http:// localhost :3000/recipe/new
  • 11. Example: a simple web application(7) Now, you can start to populate the database http://localhost:3000/recipe/new http://localhost:3000/recipe/new Click on the “create” button to add data
  • 12. Example: a simple web application(8) http://localhost:3000/recipe/list http://localhost:3000/recipe/show/1
  • 13. Example: a simple web application(9) <ul><li>Add a list method in the file “recipe_controller.rb” </li></ul><ul><li>Take over the handling of the list action from the scaffolding </li></ul>Step1:
  • 14. Example: a simple web application(10) <ul><li>Add a new file called “ list.rhtml ” under app/views/receipe </li></ul><ul><li>.rhtml : an html file with Ruby code embedded within </li></ul><ul><li>&lt;% %&gt; and </li></ul><ul><li>&lt;%= %&gt; tags </li></ul>Step2: &lt;html&gt; &lt;head&gt; &lt;title&gt;All Recipes&lt;/title&gt; &lt;/head&gt; &lt;body&gt; &lt;h1&gt;Online Cookbook - All Recipes&lt;/h1&gt; &lt;table border=&amp;quot;1&amp;quot;&gt; &lt;tr&gt; &lt;td width=&amp;quot;80%&amp;quot;&gt;&lt;p align=&amp;quot;center&amp;quot;&gt;&lt;i&gt;&lt;b&gt;Recipe&lt;/b&gt;&lt;/i&gt;&lt;/td&gt; &lt;td width=&amp;quot;20%&amp;quot;&gt;&lt;p align=&amp;quot;center&amp;quot;&gt;&lt;i&gt;&lt;b&gt;Date&lt;/b&gt;&lt;/i&gt;&lt;/td&gt; &lt;/tr&gt; &lt;% @recipes.each do |recipe| %&gt; &lt;tr&gt; &lt;td&gt; &lt;%= link_to recipe.title, :action =&gt; &amp;quot;show&amp;quot;, :id =&gt; recipe.id %&gt; &lt;/td&gt; &lt;td&gt; &lt;%= recipe.date %&gt; &lt;/td&gt; &lt;/tr&gt; &lt;% end %&gt; &lt;/table&gt; &lt;p&gt; &lt;%= link_to &amp;quot;Create new recipe&amp;quot;, :action =&gt; &amp;quot;new&amp;quot; %&gt; &lt;/p&gt; &lt;/body&gt; &lt;/html&gt;
  • 15. Example: a simple web application(11) <ul><li>Ask the recipe class for a collection of all recipes from the DB and assign the collection to the instance variable @recipes </li></ul>Step3:
  • 16. Example: a simple web application(12) http://localhost:3000/recipe/list Done!
  • 17. Pros and Cons <ul><li>pros </li></ul><ul><ul><li>Less code </li></ul></ul><ul><ul><li>High productivity &amp; reduced development time </li></ul></ul><ul><li>cons </li></ul><ul><ul><li>too young </li></ul></ul><ul><ul><li>Upgrades in foundational code may result in instability in Rails </li></ul></ul><ul><ul><ul><li>Relies on a foundation of numerous other applications </li></ul></ul></ul>
  • 18. Reference <ul><li>Russel Kay: QUICK STUDY: Ruby on Rails. Computerworld, 11/28/2005, Vol. 39 Issue 48, pg26-26 </li></ul><ul><li>David Geer: Will Software Developers Rid Ruby on Rails to Success? Computer, Feb2006, Vol. 39 Issue 2, pg18-20 </li></ul><ul><li>Stacy Cowley : Riding the ruby rails in a new direction  CRN. Jericho: Mar 13, 2006., Issue 1187;  pg. 43 </li></ul><ul><li>Grant Buckler : Application developers climb aboard Ruby on Rails  Computing Canada. Willowdale: Aug 19, 2005.Vol.31, Issue 11;  pg. 6 </li></ul><ul><li>Daniel Bogan: Get on track with ruby on rails http://www.sitepoint.com/article/ruby-on-rails </li></ul><ul><li>Curt Hibbs:What Is Ruby on Rails? http://www.onlamp.com/lpt/a/6251 </li></ul><ul><li>  Bill Walton :Rolling with Ruby on [Instant]Rails http:// instantrails . rubyforge .org/tutorial/index.html </li></ul><ul><li>Curt Hibbs: Rolling with Ruby on Rails, Part 2 http://www.onlamp.com/lpt/a/5641 </li></ul><ul><li>Curt Hibbs: Ajax on Rails http://www.onlamp.com/lpt/a/5944 </li></ul><ul><li>http://en.wikipedia.org/wiki/Ruby_On_Rails </li></ul><ul><li>http://www.rubyonrails.com/ </li></ul>

×