Ruby on rails 避免在局部视图中使用实例变量
我在控制器方法中有@productrecords和@clone_记录。将以下代码部署到暂存中时Ruby on rails 避免在局部视图中使用实例变量,ruby-on-rails,Ruby On Rails,我在控制器方法中有@productrecords和@clone_记录。将以下代码部署到暂存中时 = f.association :product, :collection => Category.products,:include_blank => "Select Product",:label => "* Product", :selected =>@productrecords.product_id ? @productrecords.product_id : @cl
= f.association :product, :collection => Category.products,:include_blank => "Select Product",:label => "* Product", :selected =>@productrecords.product_id ? @productrecords.product_id : @clone_record.product_id
我在houndci bot的部分视图中避免使用实例变量时出错
解决此问题的最佳做法是什么
对。它位于部分文件中
这就是警告/错误告诉您的:不要在部分文件中使用实例变量。相反,使用局部变量。例如:
您的部分渲染如下所示:
= render 'my_partial'
如下更改以显式传递所有变量:
= render 'my_partial', productrecords: @productrecords, clone_record: @clone_record
您的部分用户现在将使用本地用户:
= f.association :product, :collection => Category.products,:include_blank => "Select Product",
:label => "* Product",
:selected =>productrecords.product_id ? productrecords.product_id : clone_record.product_id
这条线在局部中位于何处?可以将局部渲染为“是”。这是部分文件谢谢你,吉。伟大的