Rails 5.2 ActiveStorage白名单参数

时间:2018-08-21 21:59:44

标签: ruby-on-rails rails-activestorage

我正在将Rails 5.2更新为activestorage,并获得了“ 我的create动作中未定义的方法[[] ='for nil:NilClass”。 我认为问题与我列入白名单的参数有关。我试图按照指南进行操作,但仍然无法弄清我所缺少的内容。

我的模型具有has_many_attached:images 我的控制器有

  def create
    @product = Product.new(product_params)
    @product.images.attach(params[:product][:images])

    if @product.save
      redirect_to @product, notice: 'Product was successfully created.'
    else
      render :new
    end
  end
private
    def product_params
      params.require(:product).permit(:name, :description, :category_id, :tag_list, :partialone, :partialtwo, :partialthree, :shape, :earrings, :metalweight, :sizeone, :sizetwo, :metal, :totalweightone, :totalweighttwo, :meleequant, review_attributes: [:id, :rating, :text, :author, :name], images: [] )
    end

这是完整的跟踪记录: 可标记行为(5.0.0)lib / acts_as_taggable_on / taggable / core.rb:206:in process_dirty_object' acts-as-taggable-on (5.0.0) lib/acts_as_taggable_on/taggable/core.rb:184:in set_tag_list_on' 可标记行为(5.0.0)lib / acts_as_taggable_on / taggable / core.rb:45:in tag_list=' activemodel (5.2.1) lib/active_model/attribute_assignment.rb:51:in public_send' activemodel(5.2.1)lib / active_model / attribute_assignment.rb:51:in _assign_attribute' activemodel (5.2.1) lib/active_model/attribute_assignment.rb:44:in中的_assign_attributes' activemodel(5.2.1)lib / active_model / attribute_assignment.rb:43:in each' activemodel (5.2.1) lib/active_model/attribute_assignment.rb:43:in _ assign_attributes' activerecord(5.2.1)lib / active_record / attribute_assignment.rb:23:in _assign_attributes' activemodel (5.2.1) lib/active_model/attribute_assignment.rb:35:in assign_attributes' activerecord(5.2.1)lib / active_record / core.rb:314:in initialize' activerecord (5.2.1) lib/active_record/inheritance.rb:66:in new' activerecord(5.2.1)lib / active_record / inheritance.rb:66:在new' activerecord (5.2.1) lib/active_record/persistence.rb:52:in中创建!” app / controllers / products_controller.rb:65:in create' actionpack (5.2.1) lib/action_controller/metal/basic_implicit_render.rb:6:in send_action' actionpack(5.2.1)lib / abstract_controller / base.rb:194:in process_action' actionpack (5.2.1) lib/action_controller/metal/rendering.rb:30:in process_action' actionpack(5.2.1)lib / abstract_controller / callbacks.rb:42:in block in process_action' activesupport (5.2.1) lib/active_support/callbacks.rb:132:in run_callbacks' actionpack(5.2.1)lib / abstract_controller / callbacks.rb:41:in process_action' actionpack (5.2.1) lib/action_controller/metal/rescue.rb:22:in process_action' actionpack(5.2.1)lib / action_controller / metal / instrumentation.rb:34:in block in process_action' activesupport (5.2.1) lib/active_support/notifications.rb:168:in block in instrument' activesupport(5.2.1)lib / active_support / notifications / instrumenter.rb:23:in instrument' activesupport (5.2.1) lib/active_support/notifications.rb:168:in instrument' actionpack(5.2.1)lib / action_controller / metal / instrumentation.rb:32:in process_action' actionpack (5.2.1) lib/action_controller/metal/params_wrapper.rb:256:in process_action' activerecord(5.2.1)lib / active_record / railties / controller_runtime.rb:24:在process_action' actionpack (5.2.1) lib/abstract_controller/base.rb:134:in进程中” actionview(5.2.1)lib / action_view / rendering.rb:32:in process' actionpack (5.2.1) lib/action_controller/metal.rb:191:in dispatch' actionpack(5.2.1)lib / action_controller / metal.rb:252:in dispatch' actionpack (5.2.1) lib/action_dispatch/routing/route_set.rb:52:in dispatch' actionpack(5.2.1)lib / action_dispatch / routing / route_set.rb:34:in serve' actionpack (5.2.1) lib/action_dispatch/journey/router.rb:52:in block in serve' actionpack(5.2.1)lib / action_dispatch / journey / router.rb:35:in each' actionpack (5.2.1) lib/action_dispatch/journey/router.rb:35:in serve' actionpack(5.2.1)lib / action_dispatch / routing / route_set.rb:840:in call' warden (1.2.7) lib/warden/manager.rb:36:in中的通话' 管理员(1.2.7)lib / warden / manager.rb:35:in catch' warden (1.2.7) lib/warden/manager.rb:35:in 机架(2.0.5)lib / rack / tempfile_reaper.rb:15:在call' rack (2.0.5) lib/rack/etag.rb:25:in通话中 机架(2.0.5)lib / rack / conditional_get.rb:38:in call' rack (2.0.5) lib/rack/head.rb:12:in call' actionpack(5.2.1)lib / action_dispatch / http / content_security_policy.rb:18:在call' rack (2.0.5) lib/rack/session/abstract/id.rb:232:in上下文中' 机架(2.0.5)lib / rack / session / abstract / id.rb:226:在call' actionpack (5.2.1) lib/action_dispatch/middleware/cookies.rb:670:in通话中 activerecord(5.2.1)lib / active_record / migration.rb:559:在call' actionpack (5.2.1) lib/action_dispatch/middleware/callbacks.rb:28:in通话中的“ activesupport(5.2.1)lib / active_support / callbacks.rb:98:在run_callbacks' actionpack (5.2.1) lib/action_dispatch/middleware/callbacks.rb:26:in通话中 actionpack(5.2.1)lib / action_dispatch / middleware / executor.rb:14:in call' actionpack (5.2.1) lib/action_dispatch/middleware/debug_exceptions.rb:61:in call' 网络控制台(3.5.1)lib / web_console / middleware.rb:135:在call_app' web-console (3.5.1) lib/web_console/middleware.rb:28:in中阻止通话' 网络控制台(3.5.1)lib / web_console / middleware.rb:18:在catch' web-console (3.5.1) lib/web_console/middleware.rb:18:in通话中 actionpack(5.2.1)lib / action_dispatch / middleware / show_exceptions.rb:33:在call' railties (5.2.1) lib/rails/rack/logger.rb:38:in call_app'中 railties(5.2.1)lib / rails / rack / logger.rb:26:in block in call' activesupport (5.2.1) lib/active_support/tagged_logging.rb:71:in中的已标记标签' activesupport(5.2.1)lib / active_support / tagged_logging.rb:28:在tagged' activesupport (5.2.1) lib/active_support/tagged_logging.rb:71:in标签中' 铁路(5.2.1)lib / rails / rack / logger.rb:26:在call' sprockets-rails (3.2.1) lib/sprockets/rails/quiet_assets.rb:13:in中叫' actionpack(5.2.1)lib / action_dispatch / middleware / remote_ip.rb:81:在call' request_store (1.4.1) lib/request_store/middleware.rb:19:in中调用 actionpack(5.2.1)lib / action_dispatch / middleware / request_id.rb:27:在call' rack (2.0.5) lib/rack/method_override.rb:22:in通话中 机架(2.0.5)lib / rack / runtime.rb:22:in call' activesupport (5.2.1) lib/active_support/cache/strategy/local_cache_middleware.rb:29:in call' actionpack(5.2.1)lib / action_dispatch / middleware / executor.rb:14:in call' actionpack (5.2.1) lib/action_dispatch/middleware/static.rb:127:in call' 机架(2.0.5)lib / rack / sendfile.rb:111:in call' webpacker (3.5.5) lib/webpacker/dev_server_proxy.rb:22:in perform_request' rack-proxy(0.6.4)lib / rack / proxy.rb:57:在call' railties (5.2.1) lib/rails/engine.rb:524:in通话中 机架(2.0.5)lib / rack / handler / webrick.rb:86:in service' /Users/Joseph/.rvm/rubies/ruby-2.4.0/lib/ruby/2.4.0/webrick/httpserver.rb:140:in service' /Users/Joseph/.rvm/rubies/ruby-2.4.0/lib/ruby/2.4.0/webrick/httpserver.rb:96:在run' /Users/Joseph/.rvm/rubies/ruby-2.4.0/lib/ruby/2.4.0/webrick/server.rb:290:in的start_thread块中

出于某种原因,我认为问题出在列入白名单的参数中的“图像:[]”,但不确定。有任何想法吗?谢谢。

0 个答案:

没有答案