how to build a blog with rails5 and bootstrap4

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])
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 135,314评论 19 139
  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 175,046评论 25 709
  • 听说网络组有个作业,叫做在github上写一下我搭建博客的流程 我就很为难 为什么呢 因为我也是像个傻*一样跟着教...
    皮皮虾饲养员阅读 1,768评论 0 0
  • 此时次日此刻,有这番感想,夜已深,若不记录,定是辗转反侧,所以伴着渐冷的秋风,记述此刻心情。 刚刚从高铁站出来,这...
    子玥闲叙阅读 1,644评论 2 1
  • 一看这本书的书名,就知道是Marketing指南,但是想了解书的内容,一定要先从作者研究起。这本书的作者是马修·威...
    Reneemu阅读 2,865评论 0 0