Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/oop/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails I';m获取未定义的方法'file';对于#<;尝试在没有activerecord的情况下使用carrierwave时,ActionView::Helpers::FormBuilder_Ruby On Rails_Ruby_Ruby On Rails 4_Carrierwave_Form For - Fatal编程技术网

Ruby on rails I';m获取未定义的方法'file';对于#<;尝试在没有activerecord的情况下使用carrierwave时,ActionView::Helpers::FormBuilder

Ruby on rails I';m获取未定义的方法'file';对于#<;尝试在没有activerecord的情况下使用carrierwave时,ActionView::Helpers::FormBuilder,ruby-on-rails,ruby,ruby-on-rails-4,carrierwave,form-for,Ruby On Rails,Ruby,Ruby On Rails 4,Carrierwave,Form For,我尝试上传图像,过去我使用carrierwave,发现它非常简单。这次我不使用活动记录 这是我的型号: class Garment include ActiveAttr::Model extend CarrierWave::Mount attribute :alternativeColour attribute :title attribute :image attribute :image2 attribute :image3

我尝试上传图像,过去我使用carrierwave,发现它非常简单。这次我不使用活动记录

这是我的型号:

class Garment
    include ActiveAttr::Model
    extend CarrierWave::Mount

    attribute :alternativeColour
    attribute :title
    attribute :image
    attribute :image2
    attribute :image3
    attribute :image4
    attribute :image5
    attribute :image6
    attribute :price
    attribute :favourite
    attribute :recommended
    attribute :gender
    attribute :productType
    attribute :size
    attribute :colour 
    attribute :collection

    mount_uploader :image, ImageUploader

end
class AdminpanelController < ApplicationController

  def index        
  end

  def new
    @garment = Garment.new
  end

  def create
    garment = Parse::Object.new("Garments")
    garment["title"] = params[:garment][:title]
    garment["price"] = params[:garment][:price].to_f
    garment["alternativeColour"] = params[:garment][:alternativeColour].to_bool
    garment["gender"] = params[:garment][:gender].to_i
    garment["recommended"] = params[:garment][:recommended].to_bool
    garment["productType"] = params[:garment][:productType].to_i
    garment["size"] = params[:garment][:size].to_i
    garment["colour"] = params[:garment][:colour].to_i
    garment["collection"] = params[:garment][:collection].to_i
    garment["image"] = params[:garment][:image]
    garment.save

    redirect_to adminpanel_index_path
  end
end
<%= form_for :garment, :url => adminpanel_index_path, :html => {:multipart => true} do |f| %>
  <%= f.text_field :title, :placeholder => "Title" %> <br \>
  <%= f.text_field :price, :placeholder => "Price" %> <br \>
  <%= f.file :image %>
  <%= f.submit "Create" %> <br \>
<% end %>
我的控制器:

class Garment
    include ActiveAttr::Model
    extend CarrierWave::Mount

    attribute :alternativeColour
    attribute :title
    attribute :image
    attribute :image2
    attribute :image3
    attribute :image4
    attribute :image5
    attribute :image6
    attribute :price
    attribute :favourite
    attribute :recommended
    attribute :gender
    attribute :productType
    attribute :size
    attribute :colour 
    attribute :collection

    mount_uploader :image, ImageUploader

end
class AdminpanelController < ApplicationController

  def index        
  end

  def new
    @garment = Garment.new
  end

  def create
    garment = Parse::Object.new("Garments")
    garment["title"] = params[:garment][:title]
    garment["price"] = params[:garment][:price].to_f
    garment["alternativeColour"] = params[:garment][:alternativeColour].to_bool
    garment["gender"] = params[:garment][:gender].to_i
    garment["recommended"] = params[:garment][:recommended].to_bool
    garment["productType"] = params[:garment][:productType].to_i
    garment["size"] = params[:garment][:size].to_i
    garment["colour"] = params[:garment][:colour].to_i
    garment["collection"] = params[:garment][:collection].to_i
    garment["image"] = params[:garment][:image]
    garment.save

    redirect_to adminpanel_index_path
  end
end
<%= form_for :garment, :url => adminpanel_index_path, :html => {:multipart => true} do |f| %>
  <%= f.text_field :title, :placeholder => "Title" %> <br \>
  <%= f.text_field :price, :placeholder => "Price" %> <br \>
  <%= f.file :image %>
  <%= f.submit "Create" %> <br \>
<% end %>
class AdminpanelController
我的视图(取出一些代码以节省空间):

class Garment
    include ActiveAttr::Model
    extend CarrierWave::Mount

    attribute :alternativeColour
    attribute :title
    attribute :image
    attribute :image2
    attribute :image3
    attribute :image4
    attribute :image5
    attribute :image6
    attribute :price
    attribute :favourite
    attribute :recommended
    attribute :gender
    attribute :productType
    attribute :size
    attribute :colour 
    attribute :collection

    mount_uploader :image, ImageUploader

end
class AdminpanelController < ApplicationController

  def index        
  end

  def new
    @garment = Garment.new
  end

  def create
    garment = Parse::Object.new("Garments")
    garment["title"] = params[:garment][:title]
    garment["price"] = params[:garment][:price].to_f
    garment["alternativeColour"] = params[:garment][:alternativeColour].to_bool
    garment["gender"] = params[:garment][:gender].to_i
    garment["recommended"] = params[:garment][:recommended].to_bool
    garment["productType"] = params[:garment][:productType].to_i
    garment["size"] = params[:garment][:size].to_i
    garment["colour"] = params[:garment][:colour].to_i
    garment["collection"] = params[:garment][:collection].to_i
    garment["image"] = params[:garment][:image]
    garment.save

    redirect_to adminpanel_index_path
  end
end
<%= form_for :garment, :url => adminpanel_index_path, :html => {:multipart => true} do |f| %>
  <%= f.text_field :title, :placeholder => "Title" %> <br \>
  <%= f.text_field :price, :placeholder => "Price" %> <br \>
  <%= f.file :image %>
  <%= f.submit "Create" %> <br \>
<% end %>
adminpanel_index_path,:html=>{:multipart=>true}do | f |%>
“标题”%>
“价格”%>

为什么我会出错


谢谢您的时间。

ActionView::Helpers::FormHelper
中,没有这样的方法
f.file
此方法文件用于您的表单中的#:

file_field(object_name, method, options = {})

<%= f.file_field :image %>
文件\字段(对象\名称、方法、选项={})