更新方法以一种奇怪的方式传递 id
Update method is passing id in a weird way
不知何故,我在编辑后的更新方法是将 id 作为 "show"
传递
下面是我 "update"\
时传递的参数
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"=>"kamal057@gmail.com", "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" = ORDER BY "users"."id" ASC LIMIT [["id", 1], ["LIMIT", 1]]
Shop Load (0.3ms) SELECT "shops".* FROM "shops" WHERE "shops"."id" = LIMIT [["id", 1], ["LIMIT", 1]]
Owner Load (0.5ms) SELECT "owners".* FROM "owners" WHERE "owners"."shop_id" = AND "owners"."id" = LIMIT [["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" = ]):
我的表格是,这与新所有者(和作品)的表格相同:
<%=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。
发布问题 3 秒后,我在我的路由文件中发现了这个:
get 'owners/show'#, as: :owner
并将其更改为
get 'owners/show'
看来我不需要那个别名。
在 rails 中创建 RESTful 路由的首选方法是使用资源:
resources :owners
这会给你 GET /owners/:id
这是一个规范的 Rails REST 路由,它指向 OwnersController
上的显示操作。
不要创建如下路由:
/owners/show
/owners/index
/owners/create
除非你想看起来无能。在 Rails 中,操作由使用的 HTTP 动词和末尾动态 ID 段的存在推断。
参见:
不知何故,我在编辑后的更新方法是将 id 作为 "show"
传递下面是我 "update"\
时传递的参数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"=>"kamal057@gmail.com", "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" = ORDER BY "users"."id" ASC LIMIT [["id", 1], ["LIMIT", 1]]
Shop Load (0.3ms) SELECT "shops".* FROM "shops" WHERE "shops"."id" = LIMIT [["id", 1], ["LIMIT", 1]]
Owner Load (0.5ms) SELECT "owners".* FROM "owners" WHERE "owners"."shop_id" = AND "owners"."id" = LIMIT [["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" = ]):
我的表格是,这与新所有者(和作品)的表格相同:
<%=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。
发布问题 3 秒后,我在我的路由文件中发现了这个:
get 'owners/show'#, as: :owner
并将其更改为
get 'owners/show'
看来我不需要那个别名。
在 rails 中创建 RESTful 路由的首选方法是使用资源:
resources :owners
这会给你 GET /owners/:id
这是一个规范的 Rails REST 路由,它指向 OwnersController
上的显示操作。
不要创建如下路由:
/owners/show
/owners/index
/owners/create
除非你想看起来无能。在 Rails 中,操作由使用的 HTTP 动词和末尾动态 ID 段的存在推断。
参见: