どのようにアプローチするのが最善なのかわからないという問題があります。データベースには、データを取得して表示する必要がある 3 つのテーブルがあります。
テーブル: 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