Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Cocoa on-rails-3rd

775 views

Published on

Published in: Education, Technology
  • Be the first to comment

  • Be the first to like this

Cocoa on-rails-3rd

  1. 1. Junli Blog Cocoa on Rails 3rd 2011-7-18
  2. 2. Blog
  3. 3. >rails new blog
  4. 4. Gems>cd blog>bundle install
  5. 5. SQLite3
  6. 6. >rake db:create
  7. 7. Web>rails serveror>rails s
  8. 8. http://127.0.0.1:3000127.0.0.13000
  9. 9. Say hello>rails generate controller home indexapp/views/home/index.html.erb index.html.erb<h1> Hello, Junli </h1>
  10. 10. public/index.html
  11. 11. config/routes.rb rootroot :to => “home#index” Rails root home controller
  12. 12. Post>rails generate scaffold Post name:stringtitle:string content:textrake db:migrate
  13. 13. Comment model>rails generate model Commentcommenter:string body:text post:referencesrake db:migrate rails generate
  14. 14. comment.rb app/models/comment.rbclass Comment < ActiveRecord::Base belongs_to :postend
  15. 15. ModelsModels (post) (comment)
  16. 16. Models post.rbpost.rbclass Post < ActiveRecord::Base... has_many :commentsend @post.comments
  17. 17. config/route.rbresources :post do resources :commentsend
  18. 18. Controller>rails generate controller Comments
  19. 19. Post showapp/views/posts/show.html.erbhttp://dpaste.com/hold/570758/
  20. 20. CommentsController create action class CommentsController < ApplicationController def create @post = Post.find(params[:post_id]) @comment = @post.comments.create(params[:comment]) redirect_to post_path(@post) endend
  21. 21. DonePost
  22. 22. Bloghttps://github.com/snowdon/blog

×