Introduction to Ruby on Rails<br />
This Presentation<br />Based on RailsBridge Open Workshop Project<br />http://wiki.railsbridge.org/projects/railsbridge/wi...
What we’re going to do<br />“Suggestotron”<br />Topics<br />Votes<br />
Create Rails App<br />rails suggestotron<br />ruby script/server<br />http://localhost:3000<br />
Index Page<br />public/index.html<br />
Scaffolding<br />ruby script/generate<br /> scaffold topic <br />title:string<br />description:text<br />rake db:migrate<b...
What happened?<br />Generated files<br />Migration<br />http://localhost:3000/topics<br />MVC<br />Routes<br />
Votes<br />script/generate resource vote topic_id:integer<br />
Associations<br />Topic - has_many :votes<br />Vote - belongs_to :topic <br /><ul><li>irb</li></li></ul><li>Views<br />&lt...
Controller<br />class VotesController &lt; ApplicationController<br />  def create<br />    vote = Vote.new(:topic_id =&gt...
Introduction to Rails
Upcoming SlideShare
Loading in …5
×

Introduction to Rails

783 views

Published on

Introduction to Ruby on Rails

Published in: Technology
1 Comment
1 Like
Statistics
Notes
No Downloads
Views
Total views
783
On SlideShare
0
From Embeds
0
Number of Embeds
4
Actions
Shares
0
Downloads
8
Comments
1
Likes
1
Embeds 0
No embeds

No notes for slide

Introduction to Rails

  1. 1. Introduction to Ruby on Rails<br />
  2. 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. 3. What we’re going to do<br />“Suggestotron”<br />Topics<br />Votes<br />
  4. 4. Create Rails App<br />rails suggestotron<br />ruby script/server<br />http://localhost:3000<br />
  5. 5. Index Page<br />public/index.html<br />
  6. 6. Scaffolding<br />ruby script/generate<br /> scaffold topic <br />title:string<br />description:text<br />rake db:migrate<br />
  7. 7. What happened?<br />Generated files<br />Migration<br />http://localhost:3000/topics<br />MVC<br />Routes<br />
  8. 8. Votes<br />script/generate resource vote topic_id:integer<br />
  9. 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. 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 />

×