随笔分类 -  Rails

摘要:Rails Model中使用枚举有两种方案,一种是rails内置的enum,一种使用enumerize这个gem,不管哪种都能达到相同的目的。 首先介绍第一种: 一. enum 基本使用方法,以一个案列来说明: 给已经存在的 Company 增加一个 size 属性, 属性包括 large, med 阅读全文
posted @ 2017-08-09 14:51 zhuxian300c 阅读(682) 评论(0) 推荐(0)
摘要:开发中有时遇到会将数组以字符串的形式存在mysql中,取出来的时候怎么再转换为数组呢? 阅读全文
posted @ 2017-07-06 17:55 zhuxian300c 阅读(671) 评论(0) 推荐(0)
摘要:ActiveSupport::NumberHelper.number_to_currency(amount, precision: 0) 阅读全文
posted @ 2017-07-06 16:39 zhuxian300c 阅读(212) 评论(0) 推荐(0)
摘要:1. 邮箱验证VALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-]+(\.[a-z\d\-]+)*\.[a-z]+\z/i validates :email, presence: true, length: { maximum: 255 }, format: { wi 阅读全文
posted @ 2017-06-22 11:01 zhuxian300c 阅读(168) 评论(0) 推荐(0)
摘要:之前在开发文件下载的功能时,我遇到了一个很奇怪的问题,点击下载链接,在chrome console中会出现两次请求,第一次返回200,下载的数据缓存在chrome的cache中,第二次返回304,直接从本地获取到下载的数据。查看服务器log,的确返回了两次数据。经过很长时间的定位与搜索,终于找到了问 阅读全文
posted @ 2017-06-09 16:04 zhuxian300c 阅读(309) 评论(0) 推荐(0)
摘要:1、在Gemfile中增加 gem 'bootstrap-sass', '~> 3.2.0.2'2、bundle install3、把assets/stylesheets/application.css重命名为application.scss4、在这个文件中增加: 5、在assets/javascr 阅读全文
posted @ 2017-06-09 09:57 zhuxian300c 阅读(1076) 评论(0) 推荐(0)
摘要:今天碰到一个相当棘手的问题,那就是ActiveRecord::StatementInvalid (Mysql2::Error: Incorrect string value 。 本来在本地测试是没有任何问题的,但是一到服务器上就会出错,错误为:Mysql2::Error: Incorrect str 阅读全文
posted @ 2017-06-01 15:00 zhuxian300c 阅读(975) 评论(0) 推荐(0)
摘要:1. Rails最佳实践配置管理 2.使用Redis处理model缓存 阅读全文
posted @ 2017-05-31 13:14 zhuxian300c 阅读(132) 评论(0) 推荐(0)
摘要:rails执行sidekiq任务的时候报错“can't connect to local mysql server through socket '/var/run/mysqld/mysqld.sock'”, 很好理解,就是找不到这个文件,而我机器上面文件在/tmp/mysql.sock这里, 所以 阅读全文
posted @ 2017-05-26 14:49 zhuxian300c 阅读(219) 评论(0) 推荐(0)
摘要:1.时间扩展方法: beginning_of_day,end_of_day等等 Time.now.end_of_day 2.ruby类型判断 is_a?(类型) 如:b.is_a?(Array) 阅读全文
posted @ 2017-05-23 11:30 zhuxian300c 阅读(156) 评论(0) 推荐(0)
摘要:1.生成安全的base64字符串 key = SecureRandom.urlsafe_base64 阅读全文
posted @ 2017-05-19 11:47 zhuxian300c 阅读(331) 评论(0) 推荐(0)
摘要:If you’re just learning Ruby on Rails, you may be confused as to when to generate individual models, resources or scaffolding, and what files are crea 阅读全文
posted @ 2017-05-18 10:47 zhuxian300c 阅读(352) 评论(0) 推荐(0)
摘要:我们在执行rails g controller controller_name或者rails g model model_name的时候往往会生成相应的assets文件和test,怎么不让rails帮我们生成呢? 在config/application.rb文件中增加下面的代码,其实就是对rails 阅读全文
posted @ 2017-05-17 10:36 zhuxian300c 阅读(291) 评论(0) 推荐(0)
摘要:Delegate是一种应用composite来代替extend的机制,可以有效地降低代码的耦合性。 Rails 2.2增加了delegate方法,可以十分方便地实现delegate机制。 delegate方法首先检查传入的参数,正确参数形式为:method1, :method2, ..., :met 阅读全文
posted @ 2017-05-12 16:40 zhuxian300c 阅读(433) 评论(0) 推荐(0)
摘要:React Router V4 正式版发布,该版本相较于前面三个版本有根本性变化,遵循 Just Component 的 API 设计理念。 本次升级的主要变更有: 声明式 Declarative 可组合 Composability 声明式 Declarative 可组合 Composability 阅读全文
posted @ 2017-05-08 18:06 zhuxian300c 阅读(179) 评论(0) 推荐(0)
摘要:http://www.cnblogs.com/wonyun/p/5930333.html 阅读全文
posted @ 2017-05-05 12:52 zhuxian300c 阅读(109) 评论(0) 推荐(0)
摘要:fetch api是被设计用来替换XmlHttpRequest的,详细用法如下: http://javascript.ruanyifeng.com/bom/ajax.html#toc27 阅读全文
posted @ 2017-05-04 11:47 zhuxian300c 阅读(149) 评论(0) 推荐(0)
摘要:# map 针对每个element进行变换并返回整个修改后的数组 def map_method arr1 = ["name2", "class2"] arr1.map {|num| num + "and"} print "map ====",arr1, "\n" end def map1_method arr1 = ["name2", "class2"] arr1.map! ... 阅读全文
posted @ 2017-04-26 10:07 zhuxian300c 阅读(487) 评论(0) 推荐(0)
摘要:Package Control Messages Theme - Spacegray Thanks for installing Spacegray! How to activate Activate the UI theme and color scheme by modifying your u 阅读全文
posted @ 2017-04-21 09:21 zhuxian300c 阅读(233) 评论(0) 推荐(0)
摘要:Response Class HTTP StatusCode Symbol Informational 100 :continue Success 200 :ok Redirection 300 :multiple_choices 301 :moved_permanently(重定向) 304 :n 阅读全文
posted @ 2017-04-09 07:02 zhuxian300c 阅读(291) 评论(0) 推荐(0)