我在我的应用程序中使用Rails exception_notification插件并发现它非常有用.
但是,在某些情况下,我希望捕获异常并优雅地处理它,但仍希望收到异常通知电子邮件.它似乎似乎只发送未捕获的例外.
当你已经发现异常时,是否有人知道如何强制发送电子邮件?
我正在使用Rails + Paperclip + S3.我希望使用我的一个S3存储桶将我的资产托管到Cloudfront.
我知道Cloudfront会缓存资产,但您可以通过将其配置为从源转发查询字符串来中断该缓存.
当我修改资产时,我预计会发生这种情况
updated_at
ActiveRecord对象的时间戳已更新.updated_at
时间.但是,Paperclip看起来没有正确更新updated_at
时间戳.也许它以某种方式缓存.因此,查询字符串不会更新,Cloudfront也不会中断缓存.
我的模型是:
class UserImage < ActiveRecord::Base
has_attached_file :image
end
>> ui = UserImage.find(576925)
>> ui.image.class
=> Paperclip::Attachment
>> ui.touch
>> ui.updated_at.to_i
=> 1386241041
>> ui.image.updated_at
=> 1386240937
Run Code Online (Sandbox Code Playgroud)
这两个updated_at时间戳应该是相同的.
我有一个查询,我想选择所有喜欢给定艺术家的用户.国家等也有其他一些WHERE标准.这是模式的样子.
users favourite_artists artists
+----------+------------+ +-----------+------------+ +--------+--------+
| id | country | | user_id | artist_id | | id | name |
+----------+------------+ +-----------+------------+ +--------+--------+
| 1 | gb | | 1 | 6 | | 1 | Muse |
| 2 | gb | | 1 | 5 | | 2 | RATM |
| 3 | us | | 1 | 3 | | 3 | ABBA |
| 4 | us | | 2 | 3 | …
Run Code Online (Sandbox Code Playgroud) 我有一个消息表,看起来像这样:
+------------+-------------+----------+
| sender_id | created_at | message |
+------------+-------------+----------+
| 1 | 2010-06-14 | the msg |
| 1 | 2010-06-15 | the msg |
| 2 | 2010-06-16 | the msg |
| 3 | 2010-06-14 | the msg |
+------------+-------------+----------|
Run Code Online (Sandbox Code Playgroud)
我想为每个发件人选择最近的单个邮件.
这看起来像GROUP BY sender_id和ORDER BY created_at,但我无法选择最新的消息.
我正在使用postgres,因此如果我想按该字段排序,则需要在SELECT语句中的created_at字段上使用聚合函数,因此我正在考虑做这样的事情作为初始测试
SELECT messages.sender_id, MAX(messages.created_at) as the_date
FROM messages
GROUP BY sender_id
ORDER BY the_date DESC
LIMIT 10;
Run Code Online (Sandbox Code Playgroud)
这似乎工作,但当我想选择'消息'时,我不知道在它上面使用什么聚合函数.我基本上只想要与MAX created_at对应的消息.
有没有办法解决这个问题,或者我是以错误的方式接近它?
我有一个如下所示的Messages表:
Messages
+-----+------------+-------------+--------------+
| id | sender_id | receiver_id | created_at |
+-----------------------------------------------+
| 1 | 1 | 2 | 1/1/2013 |
| 2 | 1 | 2 | 1/1/2013 |
| 3 | 2 | 1 | 1/2/2013 |
| 4 | 3 | 2 | 1/2/2013 |
| 5 | 3 | 2 | 1/3/2013 |
| 6 | 5 | 4 | 1/4/2013 |
+-----------------------------------------------+
Run Code Online (Sandbox Code Playgroud)
如果'thread'是给定sender_id和receiver_id之间的一组消息,我希望查询返回最近10个线程的最新10条消息,其中sender_id或receiver_id是给定的id.
给定user_id为5的预期输出:
+-----+------------+-------------+--------------+
| id | sender_id | receiver_id | …
Run Code Online (Sandbox Code Playgroud) 我有一个计数计算查询,我在我的Rails应用程序中运行了数千次,对于db中的每个客户.
当我在MySQL客户端中运行查询并禁用查询缓存时,查询所需的时间不超过1毫秒.
但是,当我从启用了查询输出的Rails控制台运行我的任务时,我注意到在前几次查询非常快的时候,其余查询的时间突然从不到1毫秒突然增加到大约180毫秒.
我已经减少了innodb_buffer_pool_size,以便查看行为的变化,但没有注意到任何事情.
这是控制台的输出:
EmailCampaignReport::Open Columns (143.2ms) SHOW FIELDS FROM `email_campaign_report_opens`
SQL (0.3ms) SELECT count(*) AS count_all FROM `email_campaign_report_opens` WHERE (customer_id = 332330)
SQL (0.2ms) SELECT count(*) AS count_all FROM `email_campaign_report_opens` WHERE (customer_id = 333333)
SQL (0.2ms) SELECT count(*) AS count_all FROM `email_campaign_report_opens` WHERE (customer_id = 332661)
SQL (0.1ms) SELECT count(*) AS count_all FROM `email_campaign_report_opens` WHERE (customer_id = 332326)
SQL (0.1ms) SELECT count(*) AS count_all FROM `email_campaign_report_opens` WHERE (customer_id = 332665)
SQL (0.2ms) SELECT count(*) AS count_all FROM `email_campaign_report_opens` …
Run Code Online (Sandbox Code Playgroud) 我有一个有很多User
照片的模特.我想在Active Admin中设置一个复选框过滤器来过滤那些有照片的用户.基本上是照片关联存在的地方.
class User < ActiveRecord::Base
has_many :photos
end
Run Code Online (Sandbox Code Playgroud)
是否有捷径可寻?我知道您可以过滤具有特定照片等的用户,但我还没有看到您可以通过状态过滤的示例.
我有一个Ruby/Rails应用程序.
我在postgresql数据库中有一个艺术家表,我想按名称查询.我有一些艺术家有葡萄牙角色等,并且有一些问题询问他们.
例如,一支乐队名为LegiãoUrbana.如果我从我的应用程序查询字符串"legiã",我得到以下参数:
{"action"=>"search_artist", "q"=>"legi\343", "controller"=>"home"}
Run Code Online (Sandbox Code Playgroud)
但是我从查询中收到错误
Artist.all(:conditions => "name LIKE '%#{params[:q]}%'")
PGError: ERROR: invalid byte sequence for encoding "UTF8": 0xe32527
Run Code Online (Sandbox Code Playgroud)
我应该怎么做才能转换成UTF8或以某种方式解决这个问题?