我如何在Rails中進行選擇?查詢Ruby on Rails?
SELECT Women.phone, Users.name FROM women, users WHERE (users.cellid = women.cell_id);
模型/ user.rb
class User < ActiveRecord::Base
attr_accessible :cellid, :name
belongs_to :woman
end
模型/ 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
謝謝,工作正常! –