我试图跑
heroku run rake db:migrate
Run Code Online (Sandbox Code Playgroud)
并得到了错误
不能运行超过1个自由尺寸的dynos.请参阅下文了解如何修复......
我怎样才能做到这一点?
试图创建2个方法,称为
def disable_timestamps
ActiveRecord::Base.record_timestamps = false
end
def enable_timestamps
ActiveRecord::Base.record_timestamps = true
end
Run Code Online (Sandbox Code Playgroud)
和更新方法本身:
def increment_pagehit
update_attribute(:pagehit, pagehit+1)
end
Run Code Online (Sandbox Code Playgroud)
使用回调来打开和关闭时间戳,例如:
before_update :disable_timestamps, :only => :increment_pagehit
after_update :enable_timestamps, :only => :increment_pagehit
Run Code Online (Sandbox Code Playgroud)
但它没有更新任何东西,甚至是所需的属性(pagehit).
有什么建议?我不想创建另一个表来计算分页数.
所以写这个的标准方法似乎是array.include?(object)。但是,与object.in(array)相比,我发现很难快速阅读和理解。红宝石中有这样的东西吗?
我刚刚再次遇到的示例是(user_role是一个字符串,而allowed_user_roles是一个字符串数组):
allowed_user_roles.include?(user_role)
Run Code Online (Sandbox Code Playgroud)
我知道它可能是个人喜好,但是我发现它很容易阅读和理解。
user_role.in(allowed_user_roles)
Run Code Online (Sandbox Code Playgroud)