In Application Controller I have 2 methods :
在Application Controller中我有两种方法:
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
Current user's email is inserted into Subscription table after payment is completed. So I check if the user is a paid user by looking up the current_user.email in Subscription.
付款完成后,当前用户的电子邮件将插入Subscription表。所以我通过在Subscription中查找current_user.email来检查用户是否是付费用户。
On the View I block this accordingly for pro vs non pro users.
在视图中我相应地为专业用户和非专业用户阻止此操作。
<% 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 %>
Everything works properly on my development machine which has sqlite3 db. But on pushing to heroku, a premium user is never recognized. Basically I think if pro_user.empty? does not work as expected. Any help is appreciated. Could there be rails differences in the return value of empty? method between sqlite3 and pg dbs? I have done pg:reset a few times.
在我的具有sqlite3 db的开发机器上,一切正常。但是在推送到heroku时,高级用户永远不会被识别出来。基本上我认为如果pro_user.empty?没有按预期工作。任何帮助表示赞赏。空的返回值是否存在铁路差异? sqlite3和pg dbs之间的方法?我做了pg:重置了几次。
1 个解决方案
#1
0
There are definitely problems with using different dbs in development and production environment. Queries and ORM could work differently between sqlite and postgres. Therefore, I recommend using actual local postgreSQL if you are using that on heroku. Installation is really simple. Just go to the link I provide and install.
在开发和生产环境中使用不同的dbs肯定存在问题。查询和ORM在sqlite和postgres之间的工作方式可能不同。因此,如果您在heroku上使用它,我建议使用实际的本地postgreSQL。安装非常简单。只需转到我提供的链接并安装即可。
Postgres.app
#1
0
There are definitely problems with using different dbs in development and production environment. Queries and ORM could work differently between sqlite and postgres. Therefore, I recommend using actual local postgreSQL if you are using that on heroku. Installation is really simple. Just go to the link I provide and install.
在开发和生产环境中使用不同的dbs肯定存在问题。查询和ORM在sqlite和postgres之间的工作方式可能不同。因此,如果您在heroku上使用它,我建议使用实际的本地postgreSQL。安装非常简单。只需转到我提供的链接并安装即可。
Postgres.app