Ruby on Railsの紹介

1,107 views
1,011 views

Published on

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

Published in: Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
1,107
On SlideShare
0
From Embeds
0
Number of Embeds
154
Actions
Shares
0
Downloads
4
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Ruby on Railsの紹介

  1. 1. Ruby on Rails2
  2. 2. • 2•• Ruby/Ruby on Rails/Ubuntu/C#/ 2011• Twitter: @falcon_8823• Facebook: falcon.8823
  3. 3. Ruby on Rails••• Model View Controller(MVC)• • DRY(Don’t Repeat Yourself)• • CoC(Convention over Configurarion)
  4. 4. QR http://conf-in-dev.heroku.com/
  5. 5. conf-in-dev.heroku.com
  6. 6. Ruby 1.8.7 + Rails 2.3.11Ruby 1.9.2 + Rails 3.1.0
  7. 7. Rails••••• Rails•
  8. 8. Rails• •
  9. 9. • • • •• • • •
  10. 10. $ rails new nseg‐blog$ cd nseg‐blog$ rails generate scaffold article title:string author:string body:text$ rake db:migrate$ rails server
  11. 11. http://nseg-blog-1.heroku.com/articles Create, Update Delete Read
  12. 12. ••
  13. 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. 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. 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. 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. 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. 18. http://nseg-blog-2.heroku.com/articles
  19. 19. • • •• •• • • • •

×