【发布时间】:2014-04-23 00:30:22
【问题描述】:
在应用程序控制器中,我有 2 种方法:
def current_user
@current_user ||= User.find_by_auth_token( cookies[:auth_token]) if cookies[:auth_token]
rescue ActiveRecord::RecordNotFound
end
helper_method :current_user
def pro_user
@pro_user = Subscription.where(:email => current_user.email).pluck(:email) if current_user
rescue ActiveRecord::RecordNotFound
end
helper_method :pro_user
付款完成后,当前用户的电子邮件被插入到订阅表中。所以我通过在 Subscription 中查找 current_user.email 来检查用户是否是付费用户。
在视图中,我为专业用户和非专业用户相应地屏蔽了此功能。
<% if current_user %>
<!-- logged in -->
<% if pro_user.empty? %>
<!-- Not a premium user -->
<!--Display some html that iss free but not premium content -->
<% else %>
<!-- This is a premium user -->
<!-- Display all html accordingly -->
<% end %>
<% else %>
<!-- Not logged in-->
<!-- Display html message to log in -->
<% end %>
在我的具有 sqlite3 db 的开发机器上一切正常。但是在推送到 heroku 时,高级用户永远不会被识别。基本上我认为如果 pro_user.empty?没有按预期工作。任何帮助表示赞赏。空的返回值是否存在轨道差异? sqlite3和pg dbs之间的方法?我已经完成了 pg:reset 几次。
【问题讨论】:
标签: ruby-on-rails ruby heroku pg sqlite3-ruby