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

Like this? Share it with your network

Share

Ruby on Railsの紹介

on

  • 1,043 views

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

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

Statistics

Views

Total Views
1,043
Views on SlideShare
930
Embed Views
113

Actions

Likes
0
Downloads
2
Comments
0

3 Embeds 113

http://blog.falconsrv.net 104
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の紹介 Presentation Transcript

  • 1. Ruby on Rails2
  • 2. • 2•• Ruby/Ruby on Rails/Ubuntu/C#/ 2011• Twitter: @falcon_8823• Facebook: falcon.8823
  • 3. Ruby on Rails••• Model View Controller(MVC)• • DRY(Don’t Repeat Yourself)• • CoC(Convention over Configurarion)
  • 4. QR http://conf-in-dev.heroku.com/
  • 5. conf-in-dev.heroku.com
  • 6. Ruby 1.8.7 + Rails 2.3.11Ruby 1.9.2 + Rails 3.1.0
  • 7. Rails••••• Rails•
  • 8. Rails• •
  • 9. • • • •• • • •
  • 10. $ rails new nseg‐blog$ cd nseg‐blog$ rails generate scaffold article title:string author:string body:text$ rake db:migrate$ rails server
  • 11. http://nseg-blog-1.heroku.com/articles Create, Update Delete Read
  • 12. ••
  • 13. $ rails g model comment article_id:integer user_name:stringbody:string$ rails g controller comments create destroy https://github.com/falcon8823/nseg-blog-2
  • 14. class Article < ActiveRecord::Base # # article comments # article comments has_many :comments, dependent: :delete_all # validates :title, :author, :body, presence: trueend app/model/article.rb
  • 15. class Comment < ActiveRecord::Base belongs_to :article validates :user_name, :body, presence: true# article_id attr_protected :article_idend app/model/comment.rb
  • 16. <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
  • 17. # 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
  • 18. http://nseg-blog-2.heroku.com/articles
  • 19. • • •• •• • • • •