小编Bri*_*ong的帖子

如何测试电子邮件可传递性 - 垃圾文件夹中的%

有谁知道一个很好的工具来测试你的电子邮件是否进入垃圾邮件文件夹?

我的网络应用程序会向用户生成电子邮件,我收到了很多人的回复报告"嘿,没有人回复我的消息".

我有适当的SPF规则并且运行正常(电子邮件标题显示spf传递).我也通过垃圾邮件刺客传播我的信息并且得分非常低.

还有其他想法吗?

email spam-prevention

4
推荐指数
2
解决办法
6773
查看次数

SQL查找最受欢迎的类别

我的数据库(MySQL)中有3个表.

categories (name:string)
items (name:string, category_id:int)
votes (value:int, item_id:int, created_at:datetime)
Run Code Online (Sandbox Code Playgroud)

所以一个类别有很多项目,一个项目有很多选票.

我想编写一个查询来获取最受欢迎的类别,这意味着获取其项目在过去一周内获得最多票数(向上或向下)的类别.

我开始尝试更简单的东西,只是获得受欢迎的项目,但我真的只是猜测这一点,它不起作用.

SELECT *, COUNT(votes.item_id) AS score
FROM items
JOIN votes USING(item_id)
WHERE votes.created_at > #{1.week.ago}
ORDER BY COUNT(votes.item_id) DESC LIMIT 5;
Run Code Online (Sandbox Code Playgroud)

我真的不知道我在做什么,有什么想法吗?此外,如果有人知道如何做更好的高级选择,我很乐意阅读它.MySQL文档有点神秘,我不太了解'AS'和'JOINS'.

mysql sql

4
推荐指数
1
解决办法
9839
查看次数

Rails 如何根据用户类型呈现不同的操作和视图?

我有几种不同的用户类型(买家、卖家、管理员)。

我希望它们都具有相同的 account_path URL,但使用不同的操作和视图。

我正在尝试这样的事情......

class AccountsController < ApplicationController
  before_filter :render_by_user, :only => [:show]

  def show
   # see *_show below
  end

  def admin_show
    ...
  end

  def buyer_show
    ...
  end

  def client_show
    ...
  end
end
Run Code Online (Sandbox Code Playgroud)

这就是我在 ApplicationController 中定义 render_by_user 的方式...

  def render_by_user
    action = "#{current_user.class.to_s.downcase}_#{action_name}"
    if self.respond_to?(action) 
      instance_variable_set("@#{current_user.class.to_s.downcase}", current_user) # e.g. set @model to current_user
      self.send(action)
    else
      flash[:error] ||= "You're not authorized to do that."
      redirect_to root_path
    end
  end
Run Code Online (Sandbox Code Playgroud)

它在控制器中调用正确的 *_show 方法。但仍然尝试渲染“show.html.erb”并且不查找我在那里名为“admin_show.html.erb”“buyer_show.html.erb”等的正确模板。

我知道我可以手动调用render "admin_show"每个操作,但我认为可能有一种更干净的方法可以在之前的过滤器中完成这一切。

或者有其他人看到过插件或更优雅的方式来按用户类型分解操作和视图吗?谢谢!

顺便说一句,我正在使用 Rails 3(以防有所不同)。

ruby-on-rails ruby-on-rails-3

4
推荐指数
1
解决办法
3437
查看次数

Rails中的奇怪DoubleRenderError 3

我正在尝试标准redirect_to some_path and return语法,但出于某种原因,Rails 3并不喜欢这个.

class MyController < ApplicationController
  def some_action
    redirect_to "http://www.google.com"
    return
  end
end
Run Code Online (Sandbox Code Playgroud)

给我标准的错误信息:

Render and/or redirect were called multiple times in this action. Please note that you may only call render OR redirect, and at most once per action. Also note that neither redirect nor render terminate execution of the action, so if you want to exit an action after redirecting, you need to do something like "redirect_to(...) and return".
Run Code Online (Sandbox Code Playgroud)

它引用了我redirect_to "http://www.google.com"在错误中的确切行.无法弄清楚这是怎么可能的! …

ruby-on-rails ruby-on-rails-3

4
推荐指数
1
解决办法
1522
查看次数

mail.perform_deliveries = false在ActionMailer拦截器中不起作用

我们正在使用这样的ActionMailer拦截器:

class MailerInterceptor
  def self.delivering_email(message)
    p 1
    if message.to.include?("test2@example.com")
      p 2
      message.perform_deliveries = false
    end
  end
end

Mailer.register_interceptor(MailerInterceptor)
Run Code Online (Sandbox Code Playgroud)

但它似乎没有阻止在生产或我们的测试中向该地址发送消息:

require 'spec_helper'

describe "MailerInterceptor" do
  it "should block sending to certain addresses" do
    expect{ Mailer.user_alert("test1", "test@example.com").deliver }.to change{ ActionMailer::Base.deliveries.count }.by(1)
    expect{ Mailer.user_alert("test2", "test2@example.com").deliver }.to_not change{ ActionMailer::Base.deliveries.count }
  end
end
Run Code Online (Sandbox Code Playgroud)

这是使用rails 3.2.14.

它在测试的第二行打印"2",但仍然发送电子邮件.有任何想法吗?谢谢!

ruby-on-rails actionmailer

3
推荐指数
1
解决办法
2502
查看次数

Ruby:调用方法列表,直到返回true

是否有一种很好的方法可以在ruby中进行一系列方法调用UNTIL返回true?

这是我的第一个想法,但我想可能有更好的方法:

if method_one
elsif method_two
elsif method_three
else
  puts "none worked"
end
Run Code Online (Sandbox Code Playgroud)

ruby ruby-on-rails

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

IE7将绝对定位的div放在下面,忽略了z-index

试图自己解决这个问题,到目前为止失败了.

在您开始键入主题或位置字段时显示的黄色自动完成div显示在IE7 的其他文本下方.这是网站:

http://www.universitytutor.com

设置更高的Z-index并没有解决它.适用于所有其他浏览器(IE8,FF,Chrome,Safari)但不适用于IE7.有任何想法吗?

示例http://dl.dropbox.com/u/324237/autocomplete.png

css internet-explorer-7

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

Mongo使用带排序的索引

我正在尝试优化mongodb查询.我有一个指标from_account_id,to_account_idcreated_at.但是以下查询执行完整集合扫描.

{
    "ts": {
        "$date": "2012-03-18T20:29:27.038Z"
    },
    "op": "query",
    "ns": "heroku_app2281692.transactions",
    "query": {
        "$query": {
            "$or": [
                {
                    "from_account_id": {
                        "$oid": "4f55968921fcaf0001000005"
                    }
                },
                {
                    "to_account_id": {
                        "$oid": "4f55968921fcaf0001000005"
                    }
                }
            ]
        },
        "$orderby": {
            "created_at": -1
        }
    },
    "ntoreturn": 25,
    "nscanned": 2643718,
    "responseLength": 20,
    "millis": 10499,
    "client": "10.64.141.77",
    "user": "heroku_app2281692"
}
Run Code Online (Sandbox Code Playgroud)

如果我不做or,只查询from_account_idto_account_id订单,它很快.

获得理想效果的最佳方法是什么?我应该像一个数组一样在一个字段中保留account_ids(来自和来自)或许还有更好的方法.谢谢!

mongodb mongoid

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