Presentation is loading. Please wait.

Presentation is loading. Please wait.

RUBY ON RAILS (RoR) Ishwor Khadka. Why Ruby on Rails?

Similar presentations


Presentation on theme: "RUBY ON RAILS (RoR) Ishwor Khadka. Why Ruby on Rails?"— Presentation transcript:

1 RUBY ON RAILS (RoR) Ishwor Khadka

2 Why Ruby on Rails?

3 Contents Introduction MCV Directory Structure Environment Modes Test Driven Development Rails Philosophy Why RoR stands out? References Questions?

4 Introduction open-source, full-stack framework for developing database-backed web applications according to the Model-View-Control pattern. RESTful get post put delete David Heinemeier Hansson - founder David Heinemeier Hansson shipped in Mac OS X v10.5 Leopard for the first time written in ruby programming language

5 Ruby Complete object oriented language Simple Easy to write 3.times {puts “Hello World!!!”} Output: Hello World!!! Packages called gems Core gems in Rails 3.2 Actionmailer Actionpack Activerecord Activesource Activesupport Rails Rake

6 MCV Model-Controller-View Application pattern Divides application into 3 parts Model Controller View ModelView Controller

7 Data Facilitates Creation Use of data Validation of data Persistent storage Association belongs_to, has_many, has_and_belongs_to_many etc….. Implemented with ActiveRecord::Base Class Post < ActiveRecord::Base attr_accessible :title, :content belongs_to :user validates :title, presence: true, length:{minimum:5} end Post. Create(title: "My first post”,content:”This is my first post….”) Post.find(1) Post.find_by_title(“My first post”) Post.user.name => “John” Model ActiveRecord::Base DB MySQL,Sqlite,PostGre

8 Controller Middle man between Model and View Make sense of the http request Produce appropriate output Responsible for: Fetching and saving data to the model pass appropriate data to the view Class PostsController < ApplicationController respond_to :html, :js, :json, :xml, :myCustom def index @posts=Post.all respond_with @posts end def show @post=Post.find(params[:id]) respond_with @post end www.blog.com/posts ROUTES get “/posts”,to:”posts#index” View Make use of @posts

9 View What you see html.erb- embedded ruby Content inserted into main layout file Different html tags, forms, ajax helper Custom helper file Make use of data passed by controller E.g. view for posts#index All Posts application.html.erb

10 ROUTES get “/posts”,to:”posts#index” Controller #index action Model Post<ActiveRecord::Base View app/views/posts/index

11 Directory Structure  Blog  app  bin  config  db  lib  log  public  test  tmp  vendor.gitignore config.ru Gemfile Gemfile.lock rakefile readme.rdoc Includes mcv part of application, assets and helper directory Configuration files Database schema, migration files List of gems used in the application

12 Environment Modes Three environments Test Development Production Different configuration file in /config directory test.rb development.rb production.rb Different database

13 Test Driven Development Test is written beforehand http://www.youtube.com/watch?v=UfALIVZc87c RoR promotes TDD Core testing gem included Tests file located in /tests directory Can use other testing gems RSpec Cucumber Useful in large projects

14 Rails Philosophy DRY-Don’t repeat yourself Convention over configuration http://www.youtube.com/watch?v=PQbuyKUaKFo Rails is opinionated

15 Why RoR stands out? Open source Rails philosophy Asset pipeline Compiles all the css, js files into one file respectively Decreases loading time Can be disabled if needed Large contributing rails community Very well documented Large number of gems available Video casts http://railscasts.com

16 Getting Started http://guides.rubyonrails.org/getting_started.html

17 References http://rubyonrails.org/ http://guides.rubyonrails.org http://railscasts.com http://en.wikipedia.org/wiki/Ruby_on_Rails http://youtube.com

18 QUESTIONS?


Download ppt "RUBY ON RAILS (RoR) Ishwor Khadka. Why Ruby on Rails?"

Similar presentations


Ads by Google