SlideShare a Scribd company logo
be happy with 
ruby on rails
lucas renan
Be happy with Ruby on Rails - CEUNSP Itu
Be happy with Ruby on Rails - CEUNSP Itu
guru 
sorocaba
wanna be a 
developer?
Be happy with Ruby on Rails - CEUNSP Itu
yukihiro 
matsumoto
programming language 
ruby
david 
heinemeier 
hansson
web framework 
ruby on rails
$ rails new my_app
Gemfile 
source 'https://rubygems.org' 
! 
# Bundle edge Rails instead: gem 'rails', github: 
'rails/rails' 
gem 'rails', '4.1.6' 
# Use sqlite3 as the database for Active Record 
gem 'sqlite3' 
# Use SCSS for stylesheets 
gem 'sass-rails', '~> 4.0.3' 
# Use Uglifier as compressor for JavaScript assets 
gem 'uglifier', '>= 1.3.0' 
# Use CoffeeScript for .js.coffee assets and views 
gem 'coffee-rails', '~> 4.0.0’
modularity
config/application.rb 
# Pick the frameworks you want: 
! 
require "active_model/railtie" 
require "active_record/railtie" 
require "action_controller/railtie" 
# require "action_mailer/railtie" 
require "action_view/railtie" 
require "sprockets/railtie" 
require "rails/test_unit/railtie"
environments
config/database.yml 
development: 
adapter: sqlite3 
database: db/development.sqlite3 
! 
test: 
adapter: sqlite3 
database: db/test.sqlite3 
! 
production: 
adapter: sqlite3 
database: db/production.sqlite3
$ rails g scaffold post title content:text
migrations
db/migrate/20141013174127_create_posts.rb 
class CreatePosts < ActiveRecord::Migration 
def change 
create_table :posts do |t| 
t.string :title 
t.text :content 
! 
t.timestamps 
end 
end 
end
$ rake db:migrate
models
app/models/post.rb 
class Post < ActiveRecord::Base 
end
$ rails c 
post = Post.new(title: "I love ruby") 
post.save 
#INSERT INTO "posts" (“title”) 
VALUES (?) [["title", "I love ruby”]]
$ rails c 
Post.all 
#SELECT "posts".* FROM "posts" 
! 
Post.find 1 
# SELECT "posts".* FROM "posts" WHERE 
"posts"."id" = ? LIMIT 1 [["id", 1]]
routes
$ rake routes 
Prefix Verb URI Pattern Controller#Action 
! 
posts GET /posts(.:format) posts#index 
POST /posts(.:format) posts#create 
new_post GET /posts/new(.:format) posts#new 
edit_post GET /posts/:id/edit(.:format) posts#edit 
post GET /posts/:id(.:format) posts#show 
PATCH /posts/:id(.:format) posts#update 
PUT /posts/:id(.:format) posts#update 
DELETE /posts/:id(.:format) posts#destroy
controllers
app/controllers/posts_controllers.rb 
class PostsController < ApplicationController 
! 
# GET /posts 
# GET /posts.json 
def index 
@posts = Post.all 
end
views
app/views/posts/index.html.erb 
<% @posts.each do |post| %> 
! 
<%= post.title %> 
! 
<%= link_to 'Show', post %> 
<%= link_to 'Edit', edit_post_path(post) %> 
<%= link_to 'Destroy', post, method: :delete, 
data: { confirm: 'Are you sure?' } %> 
! 
<% end %>
app/views/posts/_form.html.erb 
<%= form_for(@post) do |f| %> 
! 
<%= f.label :title %> 
<%= f.text_field :title %> 
! 
<%= f.submit %> 
! 
<% end %>
app/controllers/posts_controllers.rb 
class PostsController < ApplicationController 
! 
# POST /posts 
def create 
@post = Post.new(post_params) 
! 
respond_to do |format| 
if @post.save 
format.html { redirect_to @post, notice: 'Post 
was successfully created.' } 
else 
format.html { render :new } 
end 
end 
end
asset pipeline
app/stylesheets/application.css 
/* 
*= require_tree . 
*= require_self 
*/
app/javascripts/application.js 
//= require jquery 
//= require jquery_ujs 
//= require_tree .
app/ 
helpers/! 
mailers/! 
services/! 
uploaders/! 
presenters/! 
whatever/
tests
test/controllers/posts_controller_test.rb 
class PostsControllerTest < ActionController::TestCase 
setup do 
@post = posts(:one) 
end 
! 
test "should get index" do 
get :index 
assert_response :success 
assert_not_nil assigns(:posts) 
end
test/controllers/posts_controller_test.rb 
class PostsControllerTest < ActionController::TestCase 
setup do 
@post = posts(:one) 
end 
! 
test "should create post" do 
assert_difference('Post.count') do 
post :create, post: { title: @post.title } 
end 
! 
assert_redirected_to post_path(assigns(:post)) 
end
show me in action!
thanks :)

More Related Content

What's hot (20)

PPT
Redmine Betabeers SVQ
Ildefonso Montero
 
PDF
AngularJS meets Rails
Elena Torró
 
PDF
Using Angular with Rails
Jamie Davidson
 
PDF
How angularjs saves rails
Michael He
 
ZIP
Presentation.Key
guesta2b31d
 
PPTX
Intro to Rails Give Camp Atlanta
Jason Noble
 
PPTX
Devise and Rails
William Leeper
 
PDF
Rails-3-app-auto-generator-20100817
Tse-Ching Ho
 
PPT
jQuery Intro
Jason Noble
 
PPTX
Catalog display
Jason Noble
 
PPTX
Dash of ajax
Jason Noble
 
KEY
The Joy of Gems: Cooking up Rails Plugins
Paul McMahon
 
PDF
Pundit
Bruce White
 
PDF
RSpec. Part 1
Vladimir Dementyev
 
PDF
RSpec. Part 2
Vladimir Dementyev
 
PDF
Codeigniter : Custom Routing - Manipulate Uri
Abdul Malik Ikhsan
 
PDF
devise tutorial - 2011 rubyconf taiwan
Tse-Ching Ho
 
PDF
The story became happy with itamae
Nobutoshi Ogata
 
PDF
Building Dynamic Navigation in your Rails 4 Layout
Alexander Miller
 
KEY
Cucumber
gsterndale
 
Redmine Betabeers SVQ
Ildefonso Montero
 
AngularJS meets Rails
Elena Torró
 
Using Angular with Rails
Jamie Davidson
 
How angularjs saves rails
Michael He
 
Presentation.Key
guesta2b31d
 
Intro to Rails Give Camp Atlanta
Jason Noble
 
Devise and Rails
William Leeper
 
Rails-3-app-auto-generator-20100817
Tse-Ching Ho
 
jQuery Intro
Jason Noble
 
Catalog display
Jason Noble
 
Dash of ajax
Jason Noble
 
The Joy of Gems: Cooking up Rails Plugins
Paul McMahon
 
Pundit
Bruce White
 
RSpec. Part 1
Vladimir Dementyev
 
RSpec. Part 2
Vladimir Dementyev
 
Codeigniter : Custom Routing - Manipulate Uri
Abdul Malik Ikhsan
 
devise tutorial - 2011 rubyconf taiwan
Tse-Ching Ho
 
The story became happy with itamae
Nobutoshi Ogata
 
Building Dynamic Navigation in your Rails 4 Layout
Alexander Miller
 
Cucumber
gsterndale
 

Similar to Be happy with Ruby on Rails - CEUNSP Itu (20)

PDF
Ruby on Rails at PROMPT ISEL '11
Pedro Cunha
 
PDF
Rails 3: Dashing to the Finish
Yehuda Katz
 
PDF
Rails 3 overview
Yehuda Katz
 
PPTX
Ruby on rails3 - introduction to rails
Emad Elsaid
 
PDF
Ruby On Rails Introduction
Thomas Fuchs
 
ODP
Como programar un blog REST
Javier Vidal
 
PPT
Rail3 intro 29th_sep_surendran
SPRITLE SOFTWARE PRIVATE LIMIT ED
 
KEY
Getting started with Rails (2), Season 2
RORLAB
 
PDF
Rails 3 Beautiful Code
GreggPollack
 
PDF
Ruby On Rails Starter Kit
El Orabi Mohamed Ikbal
 
PDF
Ruby on Rails - Introduction
Vagmi Mudumbai
 
PDF
Ruby Rails Web Development
Sonia Simi
 
PDF
OSDC 2009 Rails Turtorial
Yi-Ting Cheng
 
PPTX
Learning to code for startup mvp session 3
Henry S
 
KEY
Rails Presentation (Anton Dmitriyev)
True-Vision
 
PDF
QConSP 2015 - Dicas de Performance para Aplicações Web
Fabio Akita
 
PPT
Rails review
Alan Hecht
 
PPT
Rails 101
The Active Network
 
ZIP
Rails 3 (beta) Roundup
Wayne Carter
 
PDF
Ruby on-rails-workshop
Ryan Abbott
 
Ruby on Rails at PROMPT ISEL '11
Pedro Cunha
 
Rails 3: Dashing to the Finish
Yehuda Katz
 
Rails 3 overview
Yehuda Katz
 
Ruby on rails3 - introduction to rails
Emad Elsaid
 
Ruby On Rails Introduction
Thomas Fuchs
 
Como programar un blog REST
Javier Vidal
 
Rail3 intro 29th_sep_surendran
SPRITLE SOFTWARE PRIVATE LIMIT ED
 
Getting started with Rails (2), Season 2
RORLAB
 
Rails 3 Beautiful Code
GreggPollack
 
Ruby On Rails Starter Kit
El Orabi Mohamed Ikbal
 
Ruby on Rails - Introduction
Vagmi Mudumbai
 
Ruby Rails Web Development
Sonia Simi
 
OSDC 2009 Rails Turtorial
Yi-Ting Cheng
 
Learning to code for startup mvp session 3
Henry S
 
Rails Presentation (Anton Dmitriyev)
True-Vision
 
QConSP 2015 - Dicas de Performance para Aplicações Web
Fabio Akita
 
Rails review
Alan Hecht
 
Rails 3 (beta) Roundup
Wayne Carter
 
Ruby on-rails-workshop
Ryan Abbott
 
Ad

More from Lucas Renan (16)

PDF
building an international career
Lucas Renan
 
PDF
Real Time with Rails 5
Lucas Renan
 
PDF
Be Happy With Ruby on Rails - Ecosystem
Lucas Renan
 
PDF
Seja Feliz com Ruby!
Lucas Renan
 
PDF
hey agilista, esqueceu das pessoas?
Lucas Renan
 
PDF
Open Source e Ruby on Rails - FLISOL 2013
Lucas Renan
 
PDF
Movimentando Comunidades - GURU ABC
Lucas Renan
 
PDF
Ruby on Rails - UNISO
Lucas Renan
 
PDF
REST Active Resource - 7º Encontro do GURU Sorocaba
Lucas Renan
 
PDF
Ruby on Rails + MongoDB - FATEC Sorocaba
Lucas Renan
 
PDF
Ruby on Rails - Clube Startup
Lucas Renan
 
KEY
Movimente sua comunidade local - LT RubyConf Br 2012
Lucas Renan
 
KEY
AIESEC Sorocaba - CONACT Effect
Lucas Renan
 
PDF
Teste seu código! não seja imaturo e nem bundão.
Lucas Renan
 
KEY
Ruby on Rails + MongoDB
Lucas Renan
 
KEY
Ruby on Rails + MongoDB - GURU Sorocaba
Lucas Renan
 
building an international career
Lucas Renan
 
Real Time with Rails 5
Lucas Renan
 
Be Happy With Ruby on Rails - Ecosystem
Lucas Renan
 
Seja Feliz com Ruby!
Lucas Renan
 
hey agilista, esqueceu das pessoas?
Lucas Renan
 
Open Source e Ruby on Rails - FLISOL 2013
Lucas Renan
 
Movimentando Comunidades - GURU ABC
Lucas Renan
 
Ruby on Rails - UNISO
Lucas Renan
 
REST Active Resource - 7º Encontro do GURU Sorocaba
Lucas Renan
 
Ruby on Rails + MongoDB - FATEC Sorocaba
Lucas Renan
 
Ruby on Rails - Clube Startup
Lucas Renan
 
Movimente sua comunidade local - LT RubyConf Br 2012
Lucas Renan
 
AIESEC Sorocaba - CONACT Effect
Lucas Renan
 
Teste seu código! não seja imaturo e nem bundão.
Lucas Renan
 
Ruby on Rails + MongoDB
Lucas Renan
 
Ruby on Rails + MongoDB - GURU Sorocaba
Lucas Renan
 
Ad

Recently uploaded (20)

PDF
Build It, Buy It, or Already Got It? Make Smarter Martech Decisions
bbedford2
 
PPTX
Comprehensive Risk Assessment Module for Smarter Risk Management
EHA Soft Solutions
 
PPTX
Customise Your Correlation Table in IBM SPSS Statistics.pptx
Version 1 Analytics
 
PDF
MiniTool Power Data Recovery 8.8 With Crack New Latest 2025
bashirkhan333g
 
PDF
The 5 Reasons for IT Maintenance - Arna Softech
Arna Softech
 
PPTX
Agentic Automation Journey Series Day 2 – Prompt Engineering for UiPath Agents
klpathrudu
 
PDF
MiniTool Partition Wizard Free Crack + Full Free Download 2025
bashirkhan333g
 
PPTX
Foundations of Marketo Engage - Powering Campaigns with Marketo Personalization
bbedford2
 
PPTX
Home Care Tools: Benefits, features and more
Third Rock Techkno
 
PPTX
Homogeneity of Variance Test Options IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
PDF
Empower Your Tech Vision- Why Businesses Prefer to Hire Remote Developers fro...
logixshapers59
 
PDF
Odoo CRM vs Zoho CRM: Honest Comparison 2025
Odiware Technologies Private Limited
 
PDF
[Solution] Why Choose the VeryPDF DRM Protector Custom-Built Solution for You...
Lingwen1998
 
PDF
Download Canva Pro 2025 PC Crack Full Latest Version
bashirkhan333g
 
PDF
How to Hire AI Developers_ Step-by-Step Guide in 2025.pdf
DianApps Technologies
 
PDF
AOMEI Partition Assistant Crack 10.8.2 + WinPE Free Downlaod New Version 2025
bashirkhan333g
 
PPTX
Empowering Asian Contributions: The Rise of Regional User Groups in Open Sour...
Shane Coughlan
 
PPTX
Help for Correlations in IBM SPSS Statistics.pptx
Version 1 Analytics
 
PDF
NEW-Viral>Wondershare Filmora 14.5.18.12900 Crack Free
sherryg1122g
 
PDF
SAP Firmaya İade ABAB Kodları - ABAB ile yazılmıl hazır kod örneği
Salih Küçük
 
Build It, Buy It, or Already Got It? Make Smarter Martech Decisions
bbedford2
 
Comprehensive Risk Assessment Module for Smarter Risk Management
EHA Soft Solutions
 
Customise Your Correlation Table in IBM SPSS Statistics.pptx
Version 1 Analytics
 
MiniTool Power Data Recovery 8.8 With Crack New Latest 2025
bashirkhan333g
 
The 5 Reasons for IT Maintenance - Arna Softech
Arna Softech
 
Agentic Automation Journey Series Day 2 – Prompt Engineering for UiPath Agents
klpathrudu
 
MiniTool Partition Wizard Free Crack + Full Free Download 2025
bashirkhan333g
 
Foundations of Marketo Engage - Powering Campaigns with Marketo Personalization
bbedford2
 
Home Care Tools: Benefits, features and more
Third Rock Techkno
 
Homogeneity of Variance Test Options IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
Empower Your Tech Vision- Why Businesses Prefer to Hire Remote Developers fro...
logixshapers59
 
Odoo CRM vs Zoho CRM: Honest Comparison 2025
Odiware Technologies Private Limited
 
[Solution] Why Choose the VeryPDF DRM Protector Custom-Built Solution for You...
Lingwen1998
 
Download Canva Pro 2025 PC Crack Full Latest Version
bashirkhan333g
 
How to Hire AI Developers_ Step-by-Step Guide in 2025.pdf
DianApps Technologies
 
AOMEI Partition Assistant Crack 10.8.2 + WinPE Free Downlaod New Version 2025
bashirkhan333g
 
Empowering Asian Contributions: The Rise of Regional User Groups in Open Sour...
Shane Coughlan
 
Help for Correlations in IBM SPSS Statistics.pptx
Version 1 Analytics
 
NEW-Viral>Wondershare Filmora 14.5.18.12900 Crack Free
sherryg1122g
 
SAP Firmaya İade ABAB Kodları - ABAB ile yazılmıl hazır kod örneği
Salih Küçük
 

Be happy with Ruby on Rails - CEUNSP Itu