随笔分类 - Rails
摘要:####添加 Gem````gem 'exception_notification'````#### 配置在 production.rb 里面配置邮件和添加 exception_notificaiton 配置```` # 配置邮件 config.action_mailer.delivery_me...
阅读全文
摘要:TableDefinition 的对象,就是我们在写 migrate 的时候使用的对象 t如下class SomeMigration "ActiveRecord::ConnectionAdapters::TableDefinition" end end def down ... ...
阅读全文
摘要:跟 column相关的常见的方法有:column_exists? (table_name, column_name, type = nil, options = {})add_column (table_name, column_name, type, options = {})remove_co...
阅读全文
摘要:常见的方法有 : create_table, drop_table, rename_table, change_table, table_exist?详细如下:最常见的创建表格: create_table(table_name, options={})table_name 参数可以是字符串或者是符号...
阅读全文
摘要:创建 migration 需要继承自 ActiveRecord::Migration 类,常见如下:class SomeMigration < ActiveRecord::Migration def up end def down endendclass SomeMigration < ...
阅读全文
摘要:users 表结构 ( name, address )现要让 users 表添加多个地址,于是乎有了下面的 migrationdef change unless column_exists? :users, :address_id add_column :users, :address_id...
阅读全文
摘要:在写 migrate 的时候要考虑一些意外情况,比如: Comment.all , 如果有很多 comment ,而那个时候服务器内存又不够,那么很有可能就把内存给用光。所以foreach 操作很有必要。有些时候在 运行迁移的时候会出现,某个任务迁移到一半的时候,出现异常,迁移终止了。 这个时候该怎...
阅读全文
摘要:rails 表单嵌套里面的表单提交的时候会提交外面的表单。rails 默认把里面的表单删除(即你查看html的时候会发现里面的form表单不见了)。如果 form 指定 remote: true . 但是却使用 this.form.submit(); 这个js 来提交表单的话,表单的 remot...
阅读全文
摘要:true.blank? # => falsefalse.blank? # => truetrue.present? # => truefalse.present? # => false有时候判断一个 bool 值是否存在,还是老老实实用 b == nil 来...
阅读全文
摘要:devise - 你做了好多,我确不懂你。甚至理解你都那么困难。
阅读全文
摘要:确保数据的合法性是很重要的一件事情,比如我要取得一个用户的注册时间,并对其进行格式化操作。如: user.reg_time.strftime("%Y-%m-%d"); 如果 reg_time 这个字段的数据有的记录了有的为空,就会出现上面的语句报错。对于写上面语句的人来说,用户注册时候注册时间会被记...
阅读全文
摘要:rails demo #create app called demoruby demo/script/server #start server#browser http://127.1:3000 to view you first app#创建一个 say 的控制器ruby demo/scr...
阅读全文

浙公网安备 33010602011771号