Ruby on Railsの紹介

  • 771 views
Uploaded on

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

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

More in: Technology
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
    Be the first to like this
No Downloads

Views

Total Views
771
On Slideshare
0
From Embeds
0
Number of Embeds
1

Actions

Shares
Downloads
2
Comments
0
Likes
0

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

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. • • •• •• • • • •