2016-07-22 15 views
0

Ruby on Railsスキルを練習するWebアプリケーションを作成しようとしています。私は自分のデータベースにmanufacturers, models, tints, prices'id' =(空白)のメーカーが見つかりません

  • メーカー{id, name}いくつかの実体を持っている - 店舗車のメイクを
  • モデル{id, manufacturer_id, name}から
  • 色合い{id, manufacturer_id, model_id, front, sides, rear}車のモデルを保存する - 色合いの長さが
  • を必要と格納
  • 価格{id, description, price } - 商品の価格を格納します。

私はクォータティを生成するためのページを作成しました窓の着色のためにオン。ページには、以下manufacturer, model, type of film(front), type of film(side+rear)

を選択するユーザーが

<%= form_tag('/quotation/tints/generate') do %> 
    <%= label :manufacturer_id, 'Manufacturer' %> 
    <div class="field"> 
    <%= collection_select(:tint, :manufacturer_id, Manufacturer.order(:name), :id, :name, {:prompt => "Select Manufacturer"}) %> 
    </div> 

    Model: 
    <div class="field"> 
    <%= grouped_collection_select(:tint, :model_id, Manufacturer.order(:name), :models, :name, :id, :name, {:prompt => "Select Model"}) %> 
    </div> 

    <%= label :price_front, 'Front Tint' %> 
    <div class="field"> 
     <%= collection_select(:price, :price_front, Price.order(:name), :id, :name, {:prompt => "Select Front Tint"}) %> 
    </div> 

    <%= label :price_rear, 'Size and Back Tint' %> 
    <div class="field"> 
     <%= collection_select(:price, :price_rear, Price.order(:name), :id, :name, {:prompt => "Select Side & Rear Tint"}) %> 
    </div> 
    <div class="form-group"> 
     <%= submit_tag 'Submit' %> 
    </div> 
<% end %> 

フォームフォームが送信されると、それは/quotation/tints/generateにリダイレクトしてから値を表示しなければならないためのコードであるようにするドロップダウンメニューが含まれてドロップダウンメニュー。しかし、Couldn't find Manufacturer with 'id'=というエラーが表示されました。エラーの原因となったコードは、ここでデバッグログ

{"utf8"=>"✓", 
"authenticity_token"=>"Pl2bXiRT0AoF4i0h1RCHDbuvaKJNZOkV5ULQHKxDQgZzBWWLJ2mH7ddb9akwgxbloxBIHoVaT3pcwoIGcRufpg==", 
"tint"=>{"manufacturer_id"=>"7", "model_id"=>"6"}, 
"price"=>{"price_front"=>"1", "price_rear"=>"2"}, 
"commit"=>"Submit"} 

私は、各ドロップダウン値のidがパラメータリストに正しく表示されていることがわかりますからパラメータがある

def generate 
    @manufacturers = Manufacturer.find(params[:manufacturer_id]) 
end 

の下に示されています。しかし、私は/quotation/tints/generateに値を印刷することはできませんし、製造業者またはモデルの名前を得ることもできません。ここで

routes.rbです:

get '/quotation/tints' => 'tints#quotation', :as => 'tints_quotation' 
post '/quotation/tints/generate' => 'tints#generate', :as => 'generate_tints_quotation' 

Tint.rb

class Tint < ApplicationRecord 
    has_many :manufacturers 
    has_many :models 
    belongs_to :manufacturer 
    belongs_to :model 

    validates_uniqueness_of :model_id, :scope => [:manufacturer_id] 
end 

Model.rb

class Model < ApplicationRecord 
    belongs_to :manufacturer, :dependent => :destroy 
    validates :name, :presence => true 
    validates_uniqueness_of :name, :scope => [:manufacturer_id] 

    before_save :capitalize_content 
end 

Manufacruter.rb

class Manufacturer < ApplicationRecord 
    has_many :models, :dependent => :destroy 
    validates :name, :presence => true, uniqueness: { case_sensitive: false } 

    before_save :capitalize_content 
end 

tints.controller.rb

def quotation 
    render 'quotation' 
end 

def generate 
    @manufacturers = Manufacturer.find(params[:manufacturer_id]) 
end 

generate.html.erb

<%= @manufacturers.name %> 

私はメーカーを印刷しようとしているが、私はそれを定義する複数の方法を試してみましたが、私はまだ直面しています

を選択しました同じエラー。どんな助けでも大歓迎です。

+0

はroutes.rbの唯一のルートですか? –

+0

いいえ、もっとあります。 'Rails.application.routes.drawは リソースの操作を行います。価格 リソース:色合い リソース:モデル リソース:メーカー devise_for:ユーザー のget '/引用/色合い' => 'は#引用を濃淡':=> 'としてtints_quotation ' 投稿'/quotation/tints/generate '=>' tints#generate '、:as =>' generate_tints_quotation ' #このファイルで利用可能なDSLの詳細については、http://guides.rubyonrails.org/を参照してください。 routing.html root "pages#show"、page: "index" end ' –

答えて

2

paramsでは、manufacturer_idは、paramsハッシュの直接キーではなく、tintのネストされた値です。以下を試してください:

def generate 
    @manufacturers = Manufacturer.find(params[:tint][:manufacturer_id]) 
end 
+0

' tints'テーブルから 'front、side、and rear'の値をどのように出力できますか?これは、私がやったことです。@manufacturers = Manufacturer.find(params [:tint] [:manufacturer_id]) '、' @models = Model.find(params [:tint] [:model_id]) 'テーブルをwhere句、 '@measurements = Tint.where( 'manufacturer_id' => @manufacturers).where( 'model_id' => @models)'を使用してフィルタリングします。 #

+0

のために '<%= @ measurements.front%>'を実行しようとしましたが、 '未定義のメソッド' front 'を受け取りました。新しい質問を投稿して新しい質問をしてください。スタックオーバーフローはQ&A形式を使用します。これは1つの質問、1つの受け入れられた回答を意味します。残念ながら、この形式は、複数の関連する問題をカバーするローリングディスカッションがうまくいかないことを意味します。 – MarsAtomic

関連する問題