0

どうにか奇妙な方法でIDを渡しているI「更新」\Updateメソッドは、編集後の私の更新方法は、ここで <p></p>が渡されたパラメータを見ている「ショー」としてのidを渡して、

Started PATCH "/owners/show.3328" for 127.0.0.1 at 2016-11-08 12:28:29 +0200 
Processing by OwnersController#update as 
    Parameters: {"utf8"=>"✓", "owner"=>{"name"=>"Kamal Ghool", "phone"=>"05222123123", "email"=>"[email protected]", "notes"=>"", "customer_id"=>"", "phone2"=>"", "address1"=>"Omar ben khattab St", "city"=>"Umm el fahem", "zipcode"=>"30010"}, "commit"=>"עדכון לקוח", "id"=>"show"} 
    User Load (0.9ms) SELECT "users".* FROM "users" WHERE "users"."id" = $1 ORDER BY "users"."id" ASC LIMIT $2 [["id", 1], ["LIMIT", 1]] 
    Shop Load (0.3ms) SELECT "shops".* FROM "shops" WHERE "shops"."id" = $1 LIMIT $2 [["id", 1], ["LIMIT", 1]] 
    Owner Load (0.5ms) SELECT "owners".* FROM "owners" WHERE "owners"."shop_id" = $1 AND "owners"."id" = $2 LIMIT $3 [["shop_id", 1], ["id", 0], ["LIMIT", 1]] 
Completed 404 Not Found in 31ms (ActiveRecord: 1.7ms) 
ActiveRecord::RecordNotFound (Couldn't find Owner with 'id'=show [WHERE "owners"."shop_id" = $1]): 

私のフォームは、新しい所有者(および作品)のために同じ形態である、次のとおりです。

<%=form_for @owner , remote: true do |f| %> 

    <div class="modal-body"> 
    <div class="row"> 

     <div> 

      <div class="col-md-6" style="float: right"> 
       <div class="form-group"> 

     <%#= f.hidden_field :owner_id, { :value => @owner.id } %> 

       <%= f.label 'שם לקוח', class:"control-label" %> 
       <%= f.text_field :name, class: "form-control" %> 
       </div> 

       <div class="form-group"> 
       <%= f.label 'טלפון לקוח', class: "control-label" %> 
       <%= f.text_field :phone, class: "form-control" %> 
       </div> 
       <div class="form-group"> 

       <%= f.label 'דוא"ל', class:"control-label" %> 
       <%= f.text_field :email, class: "form-control" %> 
       </div> 
       <div class="form-group"> 
       <%= f.label 'הערות ללקוח', class: "control-label" %> 
       <%= f.text_field :notes, class: "form-control" %> 
       </div> 
      </div> 
      <div class="col-md-6"> 
     <div class="form-group"> 
      <%= f.label 'ת"ז', class:"control-label" %> 
      <%= f.text_field :customer_id, class: "form-control" %> 
     </div>  
     <div class="form-group"> 
      <%= f.label 'טלפון נוסף', class: "control-label" %> 
      <%= f.text_field :phone2, class: "form-control" %> 
     </div> 
     <div class="form-group"> 
      <%= f.label 'כתובת', class:"control-label" %> 
      <%= f.text_field :address1, class: "form-control" %> 
     </div>   
     <div class="row"> 
     <div class="form-group col-xs-6"> 
      <%= f.label 'עיר', class:"control-label" %> 
      <%= f.text_field :city, class: "form-control col-xs2" %> 
     </div> 
     <div class="form-group col-xs-6"> 
         <%= f.label 'מיקוד', class:"control-label" %> 
       <%= f.text_field :zipcode, class: "form-control col-xs2" %> 

    </div>   
    </div>   

      </div> 
     </div> 

    </div> 

    </div> 

    <div class="modal-footer"> 
      <%= f.submit class: "btn btn-primary" %> 

       <%= link_to "Cancel", "#", class: "btn", data: {dismiss: "modal"} %> 
    </div> 

update.html.erbはフィンの作品と同じsave.js.erbをレンダリング新しい所有者を作成するとき。

+0

あなたはルート定義を追加することはできますか? – max

答えて

2

レールでのRESTfulなルートを作成するための好ましい方法は、リソースを使用することです:

あなた OwnersController上のshowアクションを指す標準的なRailsのRESTルートである GET /owners/:idを与えるだろう
resources :owners 

。あなたが無能見たい場合を除き

/owners/show 
/owners/index 
/owners/create 

は、以下のようなルートを作成しないでください。 Railsでは、使用されるHTTP動詞と最後に動的IDセグメントが存在することによって、アクションが推論されます。

参照:

0

3秒質問を投稿した後、私は私のルートファイルでこれを見つけた:

get 'owners/show'#, as: :owner 

get 'owners/show' 

にそれを変更し、私はそのエイリアスを必要としなかったように見えます。

+0

そのルートは、動的IDセグメントを持たないので、あなたが望むことをしません。あなたはルートを 'get 'owners /:id'、" owners#show "と宣言することができますが、リソースを使うことが望ましいです。 – max

関連する問題

 関連する問題