我正在尝试通过产品表单更新product_suppliers.该表单显示供应商表中的所有供应商,但不更新连接表.不确定错误在哪里.索引和节目显示正确的详细信息,但编辑不更新连接表.开始在这个圈子四处走动.
更新:将表格更改为下面让我接近.但仍然没有更新连接表.但是,如果我手动将行添加到连接表,则删除按预期工作.它们显示并可以删除.保存会将新的product_id添加到行中,而不是关联的supply_company_id值.我认为它是一个属性问题,但我无法看到它.
应用程序/模型/ product.rb
class Product < ActiveRecord::Base
### shortned for clarity
has_many :product_suppliers, :foreign_key => 'product_id'
has_many :supply_companies, :through => :product_suppliers
accepts_nested_attributes_for :product_suppliers, :allow_destroy => true
end
Run Code Online (Sandbox Code Playgroud)
应用程序/模型/ supply_company.rb
class SupplyCompany < ActiveRecord::Base
has_many :products, :through => :product_suppliers
has_many :product_suppliers, :foreign_key => 'supply_company_id'
end
Run Code Online (Sandbox Code Playgroud)
应用程序/模型/ product_supplier.rb
class ProductSupplier < ActiveRecord::Base
belongs_to :product
belongs_to :supply_company
accepts_nested_attributes_for :product
accepts_nested_attributes_for :supply_company
end
Run Code Online (Sandbox Code Playgroud)
/app/admin/product.rb
ActiveAdmin.register Product do
# See permitted parameters documentation:
# https://github.com/activeadmin/activeadmin/blob/master/docs/2-resource-customization.md#setting-up-strong-parameters
#
permit_params :id, :product_name, :product_description, :product_type_id, :product_category_id, :product_colour_id, …Run Code Online (Sandbox Code Playgroud) 我已经清理了我的代码,以便将以下内容作为我的表单.但是我无法从新的update.php发送数据和更新.该表单可以正常检索数据并显示它.但是在提交时我收到了ok更新消息但是数据库中的记录没有改变任何想法.的index.php
<?php
include 'connectdb.php';
// include 'query.php';
$sql = "SELECT id, WeightorMeasure FROM weightsmeasures";
$result = $conn->query($sql)
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
echo "<form action=\"update.php\"method=\"post\">";
echo "<input type=\"text\" name=\"id\" value = ".$row["id"].">";
echo "<input type=\"text\" name=\"WeightorMeasure\" value = ".$row["WeightorMeasure"] .">";
echo "<input type=\"submit\" value=\" Submit \" name=\"Update\">";
}
echo "</form>";
} else {
echo "0 results";
}
$conn->close();
?>
Run Code Online (Sandbox Code Playgroud)
update.php
<?php
include 'connectdb.php';
$wm = $_POST['id'];
$id = $_POST['WeightorMeasure'];
$sql …Run Code Online (Sandbox Code Playgroud)