美文网首页
how to build a blog with rails5

how to build a blog with rails5

作者: Jayzen | 来源:发表于2017-04-09 10:38 被阅读64次

    1.chapter1
    2.chapter2
    3.chapter3
    4.chapter4
    5.chapter5
    6.chapter6
    7.chapter7
    8.chapter8
    9.chapter9
    10.chapter10
    11.chapter11
    12.chapter12
    13.chapter13
    14.chapter14
    15.chapter15

    1.chapter1
    添加bootstrap的gem,链接

    #gemfile
    gem 'bootstrap', '~> 4.0.0.alpha6'
    
    #application.scss
    @import "bootstrap";
    
    #application.js
    //= require jquery
    //= require bootstrap-sprocket
    

    添加friendly_id这个gem

    #gemfile
    gem 'friendly_id', '~> 5.1.0' # Note: You MUST use 5.0.0 or greater for Rails 4.0+
    
    #终端
    rails generate friendly_id
    rails generate scaffold post title:string body:text description:text slug:string:uniq
    
    #post.rb
    class Post < ApplicationRecord
      extend FriendlyId
      friendly_id :title, use: :slugged
    
      def should_generate_new_friendly_id?
        title_changed?
      end
    end
    
    #post_controller.rb
    #更改方法
    User.friendly.find(params[:id])
    

    相关文章

      网友评论

          本文标题:how to build a blog with rails5

          本文链接:https://www.haomeiwen.com/subject/pkcdattx.html