小编tal*_*daa的帖子

simple_fields_for没有显示[rails 4]

我试图创建两个隐藏字段,一个显示没有问题,但另一个来自嵌套表单不会

product.rb

class Product < ActiveRecord::Base
  has_many :product_options,  dependent: :destroy
  accepts_nested_attributes_for :product_options, allow_destroy: true, :reject_if => proc { |x| x[:option_name].blank? }
  belongs_to :user
end 
Run Code Online (Sandbox Code Playgroud)

product_option.rb

class ProductOption < ActiveRecord::Base
  belongs_to :product
end
Run Code Online (Sandbox Code Playgroud)

products_controller.rb

class ProductsController < ActionController::Base
  layout "application"

  def index 
    @products = Product.all
    @current_user = Client.find_by(id: session[:client])
    if @current_user.redeemed == true 
      redirect_to root_path
    end
  end 

  def show
    @product = Product.find(params[:id])
    @product_option = @product.product_options.find(params[:id])
    @current_user = Client.find_by(id: session[:client])
    @current_user.update(:product_option => @product_option.option_name)
    @current_user.update(:selected_product => @product.id)
    render :nothing => true
  end

  private …
Run Code Online (Sandbox Code Playgroud)

ruby-on-rails hidden-field nested-attributes

12
推荐指数
1
解决办法
3116
查看次数