• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Getting started with Rails (2), Season 2
 

Getting started with Rails (2), Season 2

on

  • 1,781 views

This is the screencast of offline lecture on Rails Guides at the 2nd round of ROR Lab. Season 2

This is the screencast of offline lecture on Rails Guides at the 2nd round of ROR Lab. Season 2

Statistics

Views

Total Views
1,781
Views on SlideShare
633
Embed Views
1,148

Actions

Likes
0
Downloads
8
Comments
0

10 Embeds 1,148

http://rorlab.org 848
http://lab.wordstory.net 197
http://www.rorlab.org 44
http://localhost 39
http://kt.rorlab.org 9
http://livecoding.rorlab.org 3
http://211.60.184.138 3
http://ror.la 3
http://lvh.me 1
http://webcache.googleusercontent.com 1
More...

Accessibility

Categories

Upload Details

Uploaded via as Apple Keynote

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n

Getting started with Rails (2), Season 2 Getting started with Rails (2), Season 2 Presentation Transcript

  • ROR Lab. Season 2 - The 2nd Round -Getting Started with Rails (2) July 7, 2012 Hyoseong Choi ROR Lab.
  • A Blog Project Post ny on a mseparate form nested form e to form_for to ne m an o y Comment Tag form_for fields_for ROR Lab.
  • Using Scaffolding$ rails generate scaffold Post name:string title:string content:textScaffolding Generator • MVC • asset • helper • test unit • routing ROR Lab.
  • Creatinga Resource w scaffolding $ rails g scaffold post name title content:text invoke active_record create db/migrate/20120705045702_create_posts.rb create app/models/post.rb invoke test_unit create test/unit/post_test.rb create test/fixtures/posts.yml invoke resource_route route resources :posts invoke scaffold_controller create app/controllers/posts_controller.rb invoke erb create app/views/posts create app/views/posts/index.html.erb create app/views/posts/edit.html.erb create app/views/posts/show.html.erb create app/views/posts/new.html.erb create app/views/posts/_form.html.erb invoke test_unit create test/functional/posts_controller_test.rb invoke helper create app/helpers/posts_helper.rb invoke test_unit create test/unit/helpers/posts_helper_test.rb invoke assets invoke coffee create app/assets/javascripts/posts.js.coffee invoke scss create app/assets/stylesheets/posts.css.scss invoke scss create app/assets/stylesheets/scaffolds.css.scss ROR Lab.
  • Running a Migrationclass CreatePosts < ActiveRecord::Migration  def change    create_table :posts do |t|      t.string :name      t.string :title      t.text :content       t.timestamps    end  endend db/migrate/20100207214725_create_posts.rb ROR Lab.
  • Running a Migration$ rake db:migrate==  CreatePosts: migrating====================================================-- create_table(:posts)   -> 0.0019s==  CreatePosts: migrated (0.0020s) to Where? ROR Lab.
  • Adding a Link<h1>Hello, Rails!</h1><%= link_to "My Blog", posts_path %> app/views/home/index.html.erb Hello, Rails! My Blog ROR Lab.
  • The Modelclass Post < ActiveRecord::Base  attr_accessible :content, :name, :titleend app/models/post.rbRails ActiveModel Record database.yml ROR Lab.
  • Adding Validations class Post < ActiveRecord::Base   attr_accessible :content, :name, :title     validates :name,  :presence => true   validates :title, :presence => true,                     :length => { :minimum => 5 } end app/models/post.rb app/models/post.rb ROR Lab.
  • Using the Console $ rails console --sandbox $ rails c --sandbox Loading development environment in sandbox (Rails 3.2.6) Any modifications you make will be rolled back on exit 1.9.3p194 :001 > Post.all Post Load (0.1ms) SELECT "posts".* FROM "posts" => [] 1.9.3p194 :002 > reload! Reloading... => true ROR Lab.
  • Listing All Postsdef index  @posts = Post.all   respond_to do |format|    format.html  # index.html.erb    format.json  { render :json => @posts }  endend app/controllers/posts_controller.rb1.9.3p194 :004 > posts = Post.all Post Load (0.2ms) SELECT "posts".* FROM "posts" => []1.9.3p194 :005 > posts.class => Array1.9.3p194 :006 > post = Post.scoped Post Load (0.2ms) SELECT "posts".* FROM "posts" => []1.9.3p194 :007 > post.class => ActiveRecord::Relation ROR Lab.
  • <h1>Listing posts</h1> Rails makes all of the <table> instance variables from the  <tr> action available to the view.    <th>Name</th>    <th>Title</th>    <th>Content</th>    <th></th>    <th></th>    <th></th>  </tr> <% @posts.each do |post| %>  <tr>    <td><%= post.name %></td>    <td><%= post.title %></td>    <td><%= post.content %></td>    <td><%= link_to Show, post %></td>    <td><%= link_to Edit, edit_post_path(post) %></td>    <td><%= link_to Destroy, post, :confirm => Are you sure?,                                     :method => :delete %></td>  </tr><% end %></table> <br /> <%= link_to New post, new_post_path %> app/views/posts/index.html.erb ROR Lab.
  • The Layout : Containers for views<!DOCTYPE html><html><head>  <title>Blog</title>  <%= stylesheet_link_tag "application" %>  <%= javascript_include_tag "application" %>  <%= csrf_meta_tags %></head><body style="background: #EEEEEE;"> <%= yield %> </body> app/views/layouts/application.html.erb ROR Lab.
  • Creating New Posts def new   @post = Post.new     respond_to do |format|     format.html  # new.html.erb     format.json  { render :json => @post }   end end <h1>New post</h1>   <%= render form %> # using HTTP POST verb   <%= link_to Back, posts_path %> app/views/posts/new.html.erb ROR Lab.
  • <%= form_for(@post) do |f| %>  <% if @post.errors.any? %>  <div id="errorExplanation">    <h2><%= pluralize(@post.errors.count, "error") %> prohibited        this post from being saved:</h2>    <ul>    <% @post.errors.full_messages.each do |msg| %>      <li><%= msg %></li>    <% end %>    </ul>  </div>  <% end %>   <div class="field">    <%= f.label :name %><br />    <%= f.text_field :name %>  </div>  <div class="field">    <%= f.label :title %><br />    <%= f.text_field :title %>  </div>  <div class="field">    <%= f.label :content %><br />    <%= f.text_area :content %>  </div>  <div class="actions">    <%= f.submit %>  </div><% end %> a “Partial” template app/views/posts/_form.html.erb ROR Lab. intelligent submit helper
  • ROR Lab.
  • “create” action ROR Lab.
  • def create  @post = Post.new(params[:post])   respond_to do |format|    if @post.save      format.html  { redirect_to(@post,                    :notice => Post was successfully created.) }      format.json  { render :json => @post,                    :status => :created, :location => @post }    else      format.html  { render :action => "new" }      format.json  { render :json => @post.errors,                    :status => :unprocessable_entity }    end  endend ROR Lab.
  • Show a Post http://localhost:3000/posts/1def show  @post = Post.find(params[:id])   respond_to do |format|    format.html  # show.html.erb    format.json  { render :json => @post }  endend ROR Lab.
  • Show a Post app/views/posts/show.html.erb<p id="notice"><%= notice %></p> <p>  <b>Name:</b>  <%= @post.name %></p> <p>  <b>Title:</b>  <%= @post.title %></p> <p>  <b>Content:</b>  <%= @post.content %></p>  <%= link_to Edit, edit_post_path(@post) %> |<%= link_to Back, posts_path %> ROR Lab.
  • Editing Postsdef edit  @post = Post.find(params[:id])<h1>Editing post</h1> <%= render form %> # using HTTP PUT verb <%= link_to Show, @post %> |<%= link_to Back, posts_path %> app/views/posts/edit.html.erb ROR Lab.
  • Editing Postsdef update  @post = Post.find(params[:id])   respond_to do |format|    if @post.update_attributes(params[:post])      format.html  { redirect_to(@post,                    :notice => Post was successfully updated.) }      format.json  { head :no_content }    else      format.html  { render :action => "edit" }      format.json  { render :json => @post.errors,                    :status => :unprocessable_entity }    end  endend ROR Lab.
  • Destroying a Post def destroy   @post = Post.find(params[:id])   @post.destroy     respond_to do |format|     format.html { redirect_to posts_url }     format.json { head :no_content }   end ROR Lab.
  • Git• Linus Tobalds, 1991• for source code version control• local repository ROR Lab.
  • Gitosis• Remote repository• git clone git://eagain.net/gitosis.git• git clone git://github.com/res0nat0r/ gitosis.git• Ubuntu 11.10 -> gitosis package• Ubuntu 12.04 -> not any more but gitolite ROR Lab.
  • Gitosis• Remote repository• git clone git://eagain.net/gitosis.git• git clone git://github.com/res0nat0r/ gitosis.git• Ubuntu 11.10 -> gitosis package• Ubuntu 12.04 -> not any more but gitolite ROR Lab.
  • Local Machine Git Repository Sever git@gitserver:project.git gitosis gitolite gitorious$ git add *$ git commit$ git push Origin ROR Lab.
  • 감사합니다.
  •    ROR Lab.