蓝天,小湖,湖水中一方小筑

Rails - Fix ActiveModel::ForbiddenAttributesError in grape

最近尝试在 Grape API 中创建一个 ActiveModel ,但是在使用 new 创建的时候发现会报 ActiveModel::ForbiddenAttributesError 错误。想了想估计是碰上了 stronng parameters 的问题。按照之前的经验,那就是给参数加上一个permit,但是发现在调用 permit! 之后,grape的params变成了空字典,从而造成后续的创建出错。在网上找了一圈,结果发现 grape 自己的Github页面上就有说明,如果需要和 Rails 4 一起使用,需要加上 hashie-forbidden_attributes gem。

Rails - Reload Parent Page in iframe

最近碰到的一个问题,弹出的 iframe 窗口在做完操作并把结果返回给 controller 后,调用 renderredirect_to 时都只会刷新 iframe 中的内容,而不会将整个页面都刷新。尝试在 iframe 中提交表单时关闭 iframe 窗口,但是依然无效。最后发现还是需要借助于 Javascript ,最后的解决方案如下:

Integrate Rails with Elasticsearch - Indexing

之前写Rails在查找这块一般都是用DB内置的查询,不过上次试了下用 Elasticsearch ,比之前想像的要简单,记点东西在这吧。

这篇东西会包含下面几项内容:

  • 安装 Elasticsearch
  • 关联 Rails 与 Elasticsearch
  • 配置索引内容
  • Custom Analyzer

本文没有完整系统的介绍,更多的只是一些使用技巧。详细说明请参见官方文档

Using Rails with Redis

I have met an issue recently that the Rails site always returns 502 error for some page. After some investigation, I have found that the problem is caused by a long time query of database, which exceeds the timeout value of unicorn configuration, then the unicorn worker process will be killed and the Nginx returns 502 to user.

So the solution for this kind prblem is to put the job into some background task, and use some other method to inform the frontend when job done. Finally I choose the Redis for this task.

Playing MongoDB with Rails

This post will try to implement a web app used for recording mobile phone of cheaters. This idea is came from cooler@linuxfb, and I have used this for a presentation about GAE on 2009, and here is the slide.

NOTE: Code still under developing, the Git repo is shown at the end of article.

Tunning Rails with DTrace

This post will talk about how to do performance test of Rails program with DTrace tool. The testing will be separated into Ruby program part and database operations part. Please make sure all the tested program has provided probes to the DTrace.

NOTICE: The testing data is still under collection, this post has only DTrace script now, I will update this post after gathering enough testing data.