Your SlideShare is downloading. ×
0
Introduction to Rails
Introduction to Rails
Introduction to Rails
Introduction to Rails
Introduction to Rails
Introduction to Rails
Introduction to Rails
Introduction to Rails
Introduction to Rails
Introduction to Rails
Introduction to Rails
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

Introduction to Rails

575

Published on

Introduction to Ruby on Rails

Introduction to Ruby on Rails

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
575
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
7
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. Introduction to Ruby on Rails<br />
  • 2. This Presentation<br />Based on RailsBridge Open Workshop Project<br />http://wiki.railsbridge.org/projects/railsbridge/wiki/Workshops<br />On Slideshare<br />http://www.slideshare.net/alkeshv/introduction-to-rails-2951425<br />
  • 3. What we’re going to do<br />“Suggestotron”<br />Topics<br />Votes<br />
  • 4. Create Rails App<br />rails suggestotron<br />ruby script/server<br />http://localhost:3000<br />
  • 5. Index Page<br />public/index.html<br />
  • 6. Scaffolding<br />ruby script/generate<br /> scaffold topic <br />title:string<br />description:text<br />rake db:migrate<br />
  • 7. What happened?<br />Generated files<br />Migration<br />http://localhost:3000/topics<br />MVC<br />Routes<br />
  • 8. Votes<br />script/generate resource vote topic_id:integer<br />
  • 9. Associations<br />Topic - has_many :votes<br />Vote - belongs_to :topic <br /><ul><li>irb</li></li></ul><li>Views<br />&lt;td&gt;&lt;%= pluralize(topic.votes.length, &quot;vote&quot;) %&gt;<br />&lt;/td&gt;<br />&lt;td&gt;&lt;%= link_to &apos;+1&apos;, votes_path(:topic =&gt; topic.id), :method =&gt; :post%&gt;<br />&lt;/td&gt;<br />
  • 10. Controller<br />class VotesController &lt; ApplicationController<br /> def create<br /> vote = Vote.new(:topic_id =&gt; params[:topic]) vote.save<br /> if vote.save<br />flash[:notice] = &apos;Vote was successfully created.’<br /> else<br />flash[:notice] = &apos;Sorry we could not count your vote.’<br /> end<br />redirect_to(topics_path)<br /> end<br />end <br />

×