小编Ome*_*lam的帖子

在哪里覆盖devise gem的current_user helper方法

我如何可以覆盖CURRENT_USER色器件宝石. 实际上我需要为移动应用添加网络服务.

目前设计是管理会话和网络应用程序的'current_user'.

现在,移动应用程序会将user_id发送到服务器.我需要像这样覆盖当前用户

def current_user
  if params[:user_id].blank?
    current_user
  else
    User.find(params[:user_id])
  end   
end
Run Code Online (Sandbox Code Playgroud)

我是否需要修改devise gem作为插件?或者是其他东西 ?
请详细解释,因为我是rails的新手.

亲切的问候,

authentication rubygems devise ruby-on-rails-3 ruby-on-rails-3.1

26
推荐指数
2
解决办法
2万
查看次数

node-mysql连接池

我正在使用node-mysql模块(https://github.com/felixge/node-mysql)或(http://utahjs.com/2010/09/22/nodejs-and-mysql-introduction/).

此API处理连接池也是如此?

我的意思是每个用户请求我打电话Client.connect()来查询MySQL并释放连接:Client.end().

这是正确的方法,还是我应该只在代码中连接/断开一次.

我正在从这份文件中学习:https://github.com/felixge/node-mysql/blob/master/Readme.md

mysql database connection-pooling node.js

14
推荐指数
2
解决办法
2万
查看次数

Rails 3.2:用 json 序列化中的空字符串替换 null 值

我正在使用 Rails 3.2序列化将 ruby​​ 对象转换为 json。

例如,我已将 ruby​​ 对象序列化为以下 json

{
  "relationship":{
    "type":"relationship",
    "id":null,
    "followed_id": null
  }
}
Run Code Online (Sandbox Code Playgroud)

在我的类关系中使用以下序列化方法 < ActiveRecord::Base

def as_json(opts = {})
  {
   :type        => 'relationship',
   :id          => id,
   :followed_id => followed_id
  }
end
Run Code Online (Sandbox Code Playgroud)

我需要在响应 json 中用空字符串(即空双引号)替换 null 值。

我怎样才能实现这个目标?

此致,

ruby serialization json ruby-on-rails ruby-on-rails-3.2

3
推荐指数
1
解决办法
8246
查看次数