1

我有以下模型:

class Iosapp < ActiveRecord::Base
  belongs_to :user
  attr_accessible :active, :featured, :name, :partner

  validates :name, :presence => true
end

我通过以下方式引用与视图中的 Iosapp 对象关联的用户:

<%= @iosapp.user.email %>

在控制器中,我目前有以下内容。但是如何更改它以使其仅返回具有特定电子邮件地址的对象(例如 test@test.com)?

@iosapps = Iosapp.all
4

1 回答 1

1

尝试这个:

@iosapps = Iosapp.joins(:user).where(:users => {:email => 'test@test.com'}).all

编辑:

或者,如果您希望用户数据与 iosapp 数据一起返回,那么:

@iosapps = Iosapp.includes(:user).where(:users => {:email => 'test@test.com'}).all
于 2013-03-17T17:48:32.050 回答