[英]Rails app behaves differently on heroku vs development
在Application Controller中,我有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
付款完成后,當前用戶的電子郵件將插入到“訂閱”表中。 因此,我通過在“訂閱”中查找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幾次。
在開發和生產環境中使用不同的數據庫肯定存在問題。 在sqlite和postgres之間,查詢和ORM可能會有所不同。 因此,如果您在heroku上使用它,我建議使用實際的本地postgreSQL。 安裝真的很簡單。 只需轉到我提供並安裝的鏈接。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.