ruby获取毫秒时间戳
命令:(Time.now.to_f*1000).to_i
写此博文时结果为:1515561447624
tail -f log/health_record.log
命令:tail -f log/要查看的log文件
- 以上计划任务执行命令为
rake old_img_up:article_img_update_qiniu
rake 引擎名:install:migrations 例:rake bbs:install:migrations
rake railties:install:migrations 无需考虑引擎名拷贝migration文件至宿主
- 上图创建了一张表,表名为:
see_elders
see_content,see_image
为俩字符串类型的字段t.references :company_doctor, foreign_key: true
该代码将生成company_doctor这张表的外键及索引字段company_doctor_id
comment: "看望老人图片记录"
该代码为字段描述t.timestamps
该代码讲生成 created_at,updated两个字段
add_column :表名, :字段名, :字段类型,comment:’字段功能说明’ 添加字段
add_index :表名, :索引字段名 添加索引
add_foreign_key :表名, :关联表名(例:posts) 添加外键
rename_column :表名, :旧字段名, :新字段名 修改字段名
change_column :表名, :要修改的字段名, :要改成的字段类型, comment:”字段功能说明” 修改字段类型
remove_foreign_key :表名, :关联表名 删除外键
remove_index :表名, :索引字段 删除索引
remove_column :表名, :字段名 删除字段
rename_table :旧表名, :新表名 修改表名
drop_table :表名 删除表
- <?php
- $arr = array(1,2,3,4,5,6,7,8,9,10,11,12);
- $n = count($arr);
- $sub_n = pow(2,$n);
- $sub_array = array();
- for($i=0; $i<$sub_n; $i++){
- $m = sprintf(‘%0+’.$n.’b’,$i);
- $t_arr = array();
- for($j=0;$j<$n;$j++)
- if($m{$j}==1 && $j!=$n) $t_arr[] = $arr[$j];
- if(array_sum($t_arr)==12) echo ‘{‘.implode(‘,’, $t_arr).’}’;
- }
- ?>
输出结果为:
{12}{5,7}{4,8}{3,9}{3,4,5}{2,10}{2,4,6}{2,3,7}{1,11}{1,5,6}{1,4,7}{1,3,8}{1,2,9}{1,2,4,5}{1,2,3,6}
<%= item.item_contents.pluck(:content)%>
直接拿出content字段结果为数组<%= item.item_contents.map{|m| m.content}%>
拿出整条数据遍历出content字段结果为数组
区别:pluck写法更为简介,效率稍微较map和collect高一点。
相同:所实现的结果相同
- 脚手架的使用
- 使用例子如下:
rails g scaffold user name:string
这条命令会生成user modle,controller,view以及数据库文件
- rake db 给已有数据表添加字段
- 运行:rails generate migration add_fieldname_to_tablename
- 去生成的DB文件修改model名,以及要添加的字段备注等等
def change
`add_column :departments, :desc, :string,comment:'部门描述'`
end
- 执行数据库迁移命令:rake db:migrate
- 使用脚手架只生成controller
rails g scaffold_controller aa
即:只生成aa这个controller字段名_before_type_cast 对象后加此代码即可查看枚举前的值
- 在使用google搜索一些GEM时在搜索条件中加入
site:
+期待得到某网站结果的网址- 使用例子如下:
hexo site:github.com
这样搜索到的结果都是github的记录
- 如果需要强行使用render时 在render之后加and return 即可
- 解决办法如下:
render json: @account.errors,status: :unprocessable_entity and return