【发布时间】:2025-06-13 14:00:01
【问题描述】:
如何在 Rails 中进行选择?
SELECT Women.phone, Users.name FROM women, users WHERE (users.cellid = women.cell_id);
模型/用户.rb
class User < ActiveRecord::Base
attr_accessible :cellid, :name
belongs_to :woman
end
model/woman.rb
class Woman < ActiveRecord::Base
attr_accessible :cell_id, :phone
has_many :users
end
控制器/index.rb
def index
@variables = User.all
@phones = Woman.all
end
【问题讨论】:
标签: sql ruby-on-rails ruby-on-rails-3.2