我有一个问题,我不确定如何最好地解决。我的数据库中有三个表,我需要从中检索和显示数据。
表:Variety
,,,Trial
_Result
我有一个表格:
<%= simple_form_for :search, url: vpc_search_path do |f| %>
<%= f.input :variety_one, collection: @variety, :include_blank => false %>
<%= f.input :variety_two, collection: @variety, :include_blank => false %>
<%= f.input :irrigations, collection: @irrigations, as: :check_boxes, :input_html => {:checked => true} %>
<%= f.input :years, collection: @years, as: :check_boxes, :input_html => {:checked => true} %>
<%= f.input :regions, collection: @regions, as: :check_boxes, :input_html => {:checked => true} %>
<%= f.button :submit %>
<% end %>
我的控制器
class VpcController < ApplicationController
def index
all = Result.select(:variety_id)
@variety = Variety.where(:variety_id => all).order('variety_name DESC').pluck(:variety_id)
@years = Result.select('DISTINCT year').pluck(:year)
@regions = Trial.select('DISTINCT region_id').pluck(:region_id)
@irrigations = Trial.select('DISTINCT irrigated').pluck(:irrigated)
end
def search
@search = params[:search]
end
end
我的模特
class Vpc < ActiveRecord::Base
has_many :varieties
has_many :results
has_many :trials
end
我需要的是,一旦搜索表单完成,它就会在表格中显示结果:
Variety One | Variety Two | Difference