Ruby on Railsの紹介
Upcoming SlideShare
Loading in...5
×
 

Ruby on Railsの紹介

on

  • 1,020 views

NSEG第19回勉強会で発表した内容です.

NSEG第19回勉強会で発表した内容です.
Railsの便利さをもっといろんな人に知ってもらいたくて,発表しました.

Statistics

Views

Total Views
1,020
Views on SlideShare
910
Embed Views
110

Actions

Likes
0
Downloads
2
Comments
0

3 Embeds 110

http://blog.falconsrv.net 101
http://paper.li 5
http://www.hanrss.com 4

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

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

Ruby on Railsの紹介 Ruby on Railsの紹介 Presentation Transcript

  • Ruby on Rails2
  • • 2•• Ruby/Ruby on Rails/Ubuntu/C#/ 2011• Twitter: @falcon_8823• Facebook: falcon.8823
  • Ruby on Rails••• Model View Controller(MVC)• • DRY(Don’t Repeat Yourself)• • CoC(Convention over Configurarion) View slide
  • QR http://conf-in-dev.heroku.com/ View slide
  • conf-in-dev.heroku.com
  • Ruby 1.8.7 + Rails 2.3.11Ruby 1.9.2 + Rails 3.1.0
  • Rails••••• Rails•
  • Rails• •
  • • • • •• • • •
  • $ rails new nseg‐blog$ cd nseg‐blog$ rails generate scaffold article title:string author:string body:text$ rake db:migrate$ rails server
  • http://nseg-blog-1.heroku.com/articles Create, Update Delete Read
  • ••
  • $ rails g model comment article_id:integer user_name:stringbody:string$ rails g controller comments create destroy https://github.com/falcon8823/nseg-blog-2
  • class Article < ActiveRecord::Base # # article comments # article comments has_many :comments, dependent: :delete_all # validates :title, :author, :body, presence: trueend app/model/article.rb
  • class Comment < ActiveRecord::Base belongs_to :article validates :user_name, :body, presence: true# article_id attr_protected :article_idend app/model/comment.rb
  • <ul><% @article.comments.each do |comment| %><li><%= "#{comment.body} -- #{comment.user_name} (#{comment.created_at})" %><%= link_to , [@article,comment], confirm: , method: :delete %></li><% end %></ul><%= form_for([@article,@comment]) do |f| %><p> :<%= f.text_field :user_name %> : <%= f.text_field :body %><%= f.submit %></p><% end %> app/views/article/show.html.erb
  • # coding: utf-8class CommentsController < ApplicationController def create @comment = Comment.new(params[:comment]) @comment.article_id = params[:article_id] @article = Article.find(params[:article_id]) if @comment.save redirect_to @comment.article, notice: else redirect_to @article, notice: end end def destroy @comment = Comment.find(params[:id]) @comment.destroy redirect_to Article.find(params[:article_id]), notice: endend app/controllers/comments_controller.rb
  • http://nseg-blog-2.heroku.com/articles
  • • • •• •• • • • •