ruby on rails学习笔记(一)
来源:互联网 发布:炮萝数据 编辑:程序博客网 时间:2024/05/01 22:10
1. Models in Rails use a singular name, and their correspondingdatabase tables use a plural name. For the model to hold comments,the convention is to use thename Comment.
这段代码创建了如下的一些文件:
%th{:class => 'hilite'}
之前从一无所知开始乱看rails代码,对于数据库表格用复数,而controller用单数一直不解。比如要为blog增加一个评论功能代码如下:
$ rails generate model Comment commenter:string body:textpost:references
db/migrate/20100207235629_create_comments.rb
app/models/comment.rb
test/unit/comment_test.rb
test/fixtures/comments.yml
里面的 model/comment.rb 是单数, 而生成的数据库名是comments.
2. 在ruby代码里添加css的class:
在css文件里有这个: th.hilite { background-color : yellow; }
3. 如何使点一个表格上的一个列名而是该列按照大小排序:
首先要把这个列名, 比如 movie title 做成一个 link_to 超链接格式,指向controller的一个方法。
例子如下:
%= link_to 'movie title', title_path(:sort =>'title'), :id = 'title_header' %
title_path(:sort=> 'title')的作用是向title这个controller传递一个参数 :sort, 然后controller里面的某个方法用params[:sort]获得那个参数以后,做相应的一个操作。 最后的 :id是定义一个cssid tag.
4. 之前那个排序的方法在controller里面, 针对一个table排序,可以想象应该是取得table所有元素,然后排序。 可以参考 rails API里的ActiveRecord, 用里面的 order 和all方法。 例子:
Movie.order(params[:sort]).all
5. rails给数据库加一列数据,参考ActiveRecord::Migration, http://api.rubyonrails.org/classes/ActiveRecord/Migration.html
6. OmniAuth gem: 第三方authorization
- ruby on rails学习笔记(一)
- Ruby on Rails 学习笔记(一 Ubuntu下配置Ruby on Rails)
- Ruby on Rails学习笔记 (一)
- Ruby on Rails 开发学习笔记 一
- Ruby On Rails 开发学习笔记(一)
- ruby on rails学习(一)
- Ruby on Rails 学习一
- Ruby on rails学习笔记
- [Ruby On Rails] Rails 路由学习笔记
- Ruby on Rails笔记(一) Getting Started
- Ruby on rails 开发学习笔记(二)
- ruby on rails 学习笔记1(语法理解)
- ruby on rails 学习笔记2(引入文件)
- ruby on rails学习笔记1
- Ruby on Rails 开发学习笔记 二
- Ruby on Rails学习笔记1
- Ruby on Rails学习笔记(二 )
- Ruby on rails学习
- ubuntud下的vim插件(Ruby on rails)
- shell 脚本中关于用户输入参…
- 为PowerPoint2010文档创建自定义任务窗格
- 如何在ubuntu关闭运行在后台的rail…
- 每天一点新知识
- ruby on rails学习笔记(一)
- 计算机技术与软件专业技术资格(水…
- GCD实战2:资源竞争
- 关于git, github
- linux服务器之间建立信任关系
- GitHub教程
- linux ftp
- 关于ruby on rails的一些文章
- SHELL脚本编写的2B经历