【问题标题】:Rails app behaves differently on heroku vs developmentRails 应用程序在 heroku 与开发中的行为不同
【发布时间】: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


    【解决方案1】:

    在开发和生产环境中使用不同的数据库肯定有问题。查询和 ORM 在 sqlite 和 postgres 之间的工作方式可能不同。因此,如果您在 heroku 上使用它,我建议使用实际的本地 postgreSQL。安装真的很简单。只需转到我提供的链接并安装即可。

    Postgres.app

    【讨论】:

    • 我想是的。我认为这一行对于 postgres 的翻译并没有不同。 Subscription.where(:email => current_user.email).pluck(:email)
    猜你喜欢
    • 1970-01-01
    • 2020-07-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-09-27
    • 2015-01-01
    相关资源
    最近更新 更多