博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
arailsdemo 2
阅读量:6574 次
发布时间:2019-06-24

本文共 1849 字,大约阅读时间需要 6 分钟。

  hot3.png

使用 simple_form

#Gemfilegem 'simple_form'____________________________#Terminal> bundle   > rails g simple_form:install

Scaffold 生成 post

> rails g scaffold post title:string sequence:integer description:text> rake db:migrate

给 post model 添加 default_scope 和 一些 validates

app/models/post.rb

class Post < ActiveRecord::Base  default_scope order("sequence DESC")    validates :title, :presence => true  validates :sequence, :presence => true,                       :numericality => { :greater_than => 0 }  validates :description, :presence => trueend

给 scaffold 添加一些 CSS

public/stylesheets/scaffold.css

.simple_form label {  float: left;  width: 100px;  text-align: right;  margin: 2px 10px;}.simple_form div.input {  margin-bottom: 10px;}.simple_form div.boolean, .simple_form input[type='submit'] {  margin-left: 120px;}.simple_form div.boolean label, .simple_form label.collection_radio {  float: none;  margin: 0;}.simple_form label.collection_radio {  margin-right: 10px;  margin-left: 2px;}.simple_form .error {  clear: left;  margin-left: 120px;  font-size: 12px;  color: #D00;  display: block;}.simple_form .hint {  clear: left;  margin-left: 120px;  font-size: 12px;  color: #555;  display: block;  font-style: italic;}

改变 Post 主页

app/views/posts/index.html.haml

%h1= "Building This Site"- @posts.each do |post|  .postShow    .sequence= "#" + post.sequence.to_s    .title= link_to post.title, post    .date= l post.created_at, :format => :date        .admin      = link_to 'Edit', edit_post_path(post)      = link_to 'Destroy', post, :confirm => 'Are you sure?', :method => :delete    .clear%br.clear= link_to 'New Post', new_post_path

格式化日期

config/locales/en.yml

en:    time:        formats:            date: "%B %d, %Y"

更改 Root URL

config/routes.rb

root :to => "posts#index"

并执行:

rm publi/index.html

转载于:https://my.oschina.net/kelby/blog/193093

你可能感兴趣的文章
增加临时表空间组Oracle11g单实例
查看>>
Diff Two Arrays
查看>>
浅谈java垃圾回收机制
查看>>
shell脚本学习之for循环
查看>>
stark组件(1):动态生成URL
查看>>
169. Majority Element
查看>>
大整数加法
查看>>
下拉菜单
查看>>
C/C++中extern关键字详解
查看>>
[清华集训2014]玛里苟斯
查看>>
Doctype作用?严格模式与混杂模式如何区分?它们有何意义
查看>>
jquery选择器(可见对象,不可见对象) +判断,对象(逆序)
查看>>
0029-求最小的数
查看>>
【MVC+EasyUI实例】对数据网格的增删改查(上)
查看>>
第三章:如何建模服务
查看>>
EF CodeFirst下数据库更新
查看>>
Project Euler 345: Matrix Sum
查看>>
mysql允许远程登录
查看>>
js判断undefined类型
查看>>
问题账户需求分析
查看>>