2016-09-26 1 views
0

を作成した後、連想クラスBELONGS_TO作成し、ユーザーがフォームに記入し、親クラスを作成します - コストレール:親は私のアプリでは

その後、私は、ユーザーが追加するには戻って行くことができるようにしたいです連想クラス - コスト依存性。私は私の見解で@costを参照しようとすると

したがって、ユーザーは/コスト/ 3/cost_dependencies /新

にナビゲートします、私はゼロクラスエラーを取得し、だから私は、私のコントローラでそれにアクセスするために@cost=Cost.find(param[:id])を追加しました。

は、今私はそれはちょうど空白だCouldn't find Cost with id=エラー

を取得しています。

答えて

1

あなたのようなネストされたルートを設定していると仮定すると:そして、コストidはあなたがrake routesを実行することで確認することができ、params[:cost_id]として利用できるようになります

resources :costs do 
    resources :cost_dependencies 
end 

を。お使いのコントローラで次のように使用するので、

   cost_cost_dependencies GET  /costs/:cost_id/cost_dependencies(.:format)          cost_dependencies#index 
            POST  /costs/:cost_id/cost_dependencies(.:format)          cost_dependencies#create 
      new_cost_cost_dependency GET  /costs/:cost_id/cost_dependencies/new(.:format)         cost_dependencies#new 
      edit_cost_cost_dependency GET  /costs/:cost_id/cost_dependencies/:id/edit(.:format)        cost_dependencies#edit 
       cost_cost_dependency GET  /costs/:cost_id/cost_dependencies/:id(.:format)         cost_dependencies#show 
            PATCH /costs/:cost_id/cost_dependencies/:id(.:format)         cost_dependencies#update 
            PUT  /costs/:cost_id/cost_dependencies/:id(.:format)         cost_dependencies#update 
            DELETE /costs/:cost_id/cost_dependencies/:id(.:format)         cost_dependencies#destroy 
           costs GET  /costs(.:format)                 costs#index 
            POST  /costs(.:format)                 costs#create 
          new_cost GET  /costs/new(.:format)                costs#new 
          edit_cost GET  /costs/:id/edit(.:format)               costs#edit 
           cost GET  /costs/:id(.:format)                costs#show 
            PATCH /costs/:id(.:format)                costs#update 
            PUT  /costs/:id(.:format)                costs#update 
            DELETE /costs/:id(.:format)                costs#destroy 

@cost = Cost.find(param[:cost_id]) 
+0

は助けが高く評価され、ありがとうあなたは、次のように表示されます – Avir94

関連する問題