小编Nat*_*han的帖子

无需推送或配置更改即可重新编译Heroku slug

我想知道是否有办法迫使Heroku重新编译slug而不推送新的提交和/或更新配置变量.

我为什么要这样做?:

我在Heroku上使用Cedar堆栈来获取Rails 3.2应用程序,我遇到了rake assets:precompile任务失败的问题(仅在编译期间 - 以后它可以正常工作heroku run).我非常怀疑这是由于在slug编译期间某些环境变量不可用,我认为heroku labs:enable user_env_compile实验性功能将解决这个问题.

但是,在user_env_compile打开该功能的情况下,配置更改不会触发重新编译slug,并且我的代码没有更改,所以我没有任何新的提交要推送.

当然,我可以通过一个微不足道的改变推动"虚拟"提交,这可能是最简单的答案---但我想知道是否有一个heroku命令可以让我直接重新编译slug.

谢谢!

heroku

136
推荐指数
6
解决办法
5万
查看次数

github部署密钥:如何为单个机器授权多个存储库

所以,我有一个主持人,称之为rob.我使用ssh-keygen rob来获取一个公钥,我在为存储库添加一个新的部署密钥屏幕时给了github cheech.现在我想部署chongrob为好.但是,如果我去添加新的部署关键屏幕仓库chong在github上,并粘贴在公共密钥我生成的rob,它说key already in use.我想,如果他们的密钥被使用,我可以克隆chong,rob但是说允许被拒绝.

很明显,这比我想象的要复杂得多,它涉及多个键或其他东西.我应该怎么做克隆chongrob

谢谢您的帮助.

github ssh-keys

36
推荐指数
3
解决办法
2万
查看次数

用于像素密度的CSS媒体查询:-moz-min-device-pixel-ratio与min-moz-device-pixel-ratio

当使用CSS媒体查询设备像素密度时,我已经看到了-moz-min-device-pixel-ratiomin--moz-device-pixel-ratio.

例如:

@media 
  only screen and (-moz-min-device-pixel-ratio: 1.5) {
  /* styles go here */
}
Run Code Online (Sandbox Code Playgroud)

@media 
  only screen and (min--moz-device-pixel-ratio: 1.5) {
  /* styles go here*/
}
Run Code Online (Sandbox Code Playgroud)

哪个是对的?

一些使用前者的教程/博客:

一些使用后者的教程/博客,包括mozilla.org:

css mobile css3 media-queries

13
推荐指数
1
解决办法
8031
查看次数

渴望从Rails 5中的实例化ActiveRecord对象加载单一关联的关联

我有一个模型User,那个has_one :childChild模型has_one :toy.

如果我有一个User类的单个实例,user我如何在一个查询中加载子和玩具?

这是不起作用的:

user.child.toy # 2 queries
user.includes(child: :toy) # can't call includes on a single record
user.child.includes(:toy) # same as above
user.association(:child).scope.eager_load(:toy).first # makes the appropriate query with both child and toy... but doesn't set the object on the user model.
user.child = user.association(:child).scope.eager_load(:toy).first # makes the appropriate query, but also calls another query before setting the child :(
Run Code Online (Sandbox Code Playgroud)

有没有办法做到这一点,不涉及重新查询用户模型.即.我想避免这种情况

User.where(id: user.id).eager_load(child: :toy).first
Run Code Online (Sandbox Code Playgroud)

Relavant模型声明:

class User < …
Run Code Online (Sandbox Code Playgroud)

ruby-on-rails rails-activerecord

13
推荐指数
2
解决办法
472
查看次数

是:on =>:对Rails 3.2.3中的before_save回调创建有效

如您所知,before_save回调在before_create回调之前执行.

因此,有些人建议使用in before_save :method, :on => :create而不是before_create使得回调方法在适当的时间执行与其他回调(例如自动保存回调)相关.例如,请参阅此Pivotal Labs博客文章以及此StackOverflow答案.

但是,据我所知,该:on => :create选项无法实现对before_save回调的预期效果.换句话说,无论是否为创建,都会为每次保存执行回调.

:on => :create选项似乎是有效的before_validation回调,虽然.

有人可以确认是否:on => :create应该适用于before_save?它是否在以前的Rails版本中有效并且现在已经坏了,或者前面提到的链接是错误的?

假设:on => :create无效,以下是否可接受,和/或有更好的方法吗?

before_save :callback_method, :if => :new_record?
Run Code Online (Sandbox Code Playgroud)

谢谢.

activerecord ruby-on-rails before-save ruby-on-rails-3.2

8
推荐指数
1
解决办法
1万
查看次数

为Heroku外部MySQL数据库连接指定SSL

我在Heroku的Cedar堆栈上运行Rails 3.2应用程序.

我正在使用Amazon RDS作为我的MySQL数据库,我在Heroku配置变量中设置了正确的DATABASE_URL.

如何让Heroku在与Amazon RDS的连接中使用SSL?

通常这将被指定为database.yml中的值,但由于Heroku为我们生成了database.yml,我不知道如何控制此设置.

谢谢!

mysql ssl heroku ruby-on-rails-3

7
推荐指数
2
解决办法
5029
查看次数

如何在rails迁移时在ruby中设置主键?

如何为我的IdClient字段设置主键?我已经尝试了所有方法,但我会收到错误(rails 3.0.9)...你能帮帮我吗?

class CreateCustomers < ActiveRecord::Migration
  def self.up
    create_table :customers do |t|
      t.integer :IdCustomer
      t.string :username
      t.string :crypted_password
      t.string :password_salt
      t.string :persistence_token
      t.string :email
      t.string :Skype
      t.string :ICQ
      t.string :Firstname
      t.string :Lastname
      t.string :Country
      t.string :State
      t.string :City
      t.string :Street
      t.string :Building
      t.integer :Room
      t.string :AddressNote
      t.date :DateOfReg
      t.integer :CustGroup
      t.float :TotalBuy

      t.timestamps
      add_index(:customers, :IdCustomer, :unique => true)
    end
  end

  def self.down
    drop_table :customers
  end
end
Run Code Online (Sandbox Code Playgroud)

还有如何在模型中设置关系?

migration ruby-on-rails

7
推荐指数
1
解决办法
2万
查看次数

使用 STI 时是否可以从包含关联中提取?

我在 Rails 4 中有以下使用单表继承 (STI) 的模型:

class User < ActiveRecord::Base
  has_many :notes
end

class Item < ActiveRecord::Base
end

#inherits from Item
class Folder < Item
  belongs_to :folder
end

#inherits from Item
class Note < Item
  belongs_to :folder
end
Run Code Online (Sandbox Code Playgroud)

我想执行以下查询,该查询应该提取笔记的 id 及其所属文件夹的名称。

user = User.first
user.notes.includes(:folder).pluck(:id, :'folders.name').first
Run Code Online (Sandbox Code Playgroud)

这将返回以下错误:

ERROR:  missing FROM-clause entry for table "folders"
Run Code Online (Sandbox Code Playgroud)

由于笔记和文件夹都继承自 Item,因此只有一个项目表,我无法从包含文件夹中提取它。

如果我做:

user = User.first
user.notes.includes(:folder).pluck(:id, :'items.name').first
Run Code Online (Sandbox Code Playgroud)

它返回笔记的名称,而不是所属的文件夹(因为笔记和文件夹都继承自 Item 并且都在项目表中)。有没有办法从包含的文件夹而不是笔记中提取?

ruby-on-rails single-table-inheritance ruby-on-rails-4

5
推荐指数
1
解决办法
2195
查看次数

在模块中创建全局Rails方法?

我需要创建一个可以在任何情况下使用的方法(MVC,测试等).而不是在environments.rbid 中填充它就像创建一个模块并将其包含为gem.为了让Rails识别这个模块中的方法,我需要在我的gem中扩展什么类?

更新:

我正在寻找一种解决方案,允许我在没有模块前缀的情况下调用我的方法.

ruby ruby-on-rails

2
推荐指数
1
解决办法
1082
查看次数

如何在Ruby中访问此JSON API数据?

我正在编写一个简短的Ruby程序,它将采用一个邮政编码并返回该邮政编码2英里范围内的城市名称.我成功调用了API并能够解析JSON数据,但我不确定如何访问"city"键.

url = API call (not going to replicate here since it requires a key)

uri = URI(url)

response = Net::HTTP.get(uri)
JSON.parse(response)
Run Code Online (Sandbox Code Playgroud)

这是我的JSON的样子.

{
  "results": [
    {
      "zip": "08225",
      "city": "Northfield",
      "county": "Atlantic",
      "state": "NJ",
      "distance": "0.0"
    },
    {
      "zip": "08221",
      "city": "Linwood",
      "county": "Atlantic",
      "state": "NJ",
      "distance": "1.8"
    }
  ]
}
Run Code Online (Sandbox Code Playgroud)

我一直试图像这样访问'城市':

response['result'][0]['city']
Run Code Online (Sandbox Code Playgroud)

这似乎是不正确的.也试过了

response[0][0]['city'] 
Run Code Online (Sandbox Code Playgroud)

以及相同代码的其他几种排列.

如何从JSON数据中获取值'Northfield'?

ruby json

2
推荐指数
1
解决办法
219
查看次数