Ruby 无法使用回形针上载图像
在我的rails应用程序中,我有一个分为两步的客户表单。在第一步中,客户输入他的详细信息、徽标和pdf,然后在下一步中选择他喜欢的主题 我的客户是你的管制员Ruby 无法使用回形针上载图像,ruby,ruby-on-rails-4,paperclip,Ruby,Ruby On Rails 4,Paperclip,在我的rails应用程序中,我有一个分为两步的客户表单。在第一步中,客户输入他的详细信息、徽标和pdf,然后在下一步中选择他喜欢的主题 我的客户是你的管制员 def new if current_user.admin? @customer = Customer.new @customer.additional_fields.build else redirect_to root_path, notice: 'You dont have admin permissions'
def new
if current_user.admin?
@customer = Customer.new
@customer.additional_fields.build
else
redirect_to root_path, notice: 'You dont have admin permissions'
end
end
def edit
if current_user.admin?
@customer = Customer.find(params[:id])
else
redirect_to root_path, notice: 'You dont have admin permissions'
end
end
def theme_selector
@customer_id = params[:customer_id]
puts @customer_id
end
def create
Rails.logger.debug "PARAMS:"
params.each do |k,v|
Rails.logger.debug "#{k}: #{v}"
end
if current_user.admin?
@customer = Customer.new(customer_params)
respond_to do |format|
if @customer.save
format.html do
redirect_to @customer, notice: 'Customer was successfully created.'
end
format.json { render :show, status: :created, location: @customer }
else
format.html { render :new }
format.json do
render json: @customer.errors, status: :unprocessable_entity
end
end
end
else
redirect_to root_path, notice: 'You dont have admin permissions'
end
end
_form.html.erb
<%= form_for @customer, url: theme_selector_path,:method => :post,html: { multipart: true } do |f| %>
<input type="hidden" name="customer_id" value="<%= @customer.id %>">
<% if @customer.errors.any? %>
<div id="error_explanation">
<h2>
<%= "#{pluralize(@customer.errors.count, "error")} prohibited this customer from being saved:" %>
</h2>
<ul>
<% @customer.errors.full_messages.each do |msg| %>
<li>
<%= msg %>
</li>
<% end %>
</ul>
</div>
<% end %>
<div class="form-group">
<%= f.label :name %>
<%= f.text_field :name, class:"form-control" %>
</div>
<div class="form-group">
<%= f.label :address %>
<%= f.text_field :address, class:"form-control" %>
</div>
<div class="form-group">
<%= f.label :affiliate_id %>
<%= f.text_field :affiliate_id, class:"form-control" %>
</div>
<div class="control-group">
<%= f.label :logo, :class => 'control-label' %>
<div class="controls">
<%= f.file_field :logo,accept: 'image/png,image/gif,image/jpeg, image/jpg' %>
</div>
</div>
<div class="form-group">
<label>Upload File</label>
<%= f.file_field :file,accept: 'application/pdf' %>
</div>
<div class="form-group">
<% f.fields_for :additional_fields do | ing | %>
<%= ing.text_field :key, :size => 50 %>
<%= ing.text_field :value, :size => 50 %>
<% end %>
</div>
<div class="actions">
<div class="row">
<div class="col-md-5">
<span><%= f.submit 'Save', class: "btn-addmore" %></span>
<span><!--%= link_to 'Back', customers_path, class: "btn btn-danger" %--> </span>
</div>
<div class="col-md-2 col-md-offset-4">
<%= link_to "next", theme_selector_path, class: "btn-update" %>
</div>
</div>
</div>
<% end %>
:post,html:{multipart:true}do | f |%>
-
'控件标签'%>
上载文件
50 %>
50 %>
我在theme_selector.html.erb上有一个submit按钮来创建客户。但在客户控制器创建操作中,我遇到了一个错误“回形针::AdapterRegistry::NoHandlerError(找不到“#”)”
开发日志:
Processing by CustomersController#create as HTML
Parameters: {"customer"=>{"name"=>"test", "address"=>"test", "affiliate_id"=>"test", "category"=>"", "domain"=>"test@web.com", "phone"=>"1111111111", "contact"=>"1214521", "email"=>"test@malibu.com", "comments"=>"none", "logo"=>"# <ActionDispatch::Http::UploadedFile:0x007f3f4946c258>", "file"=>"#<ActionDispatch::Http::UploadedFile:0x007f3f4946c208>"}}
PARAMS:
customer: #<ActionController::Parameters:0x007f3f442c0058>
controller: customers
action: create
Completed 500 Internal Server Error in 10ms (ActiveRecord: 1.0ms)
Paperclip::AdapterRegistry::NoHandlerError (No handler found for "# <ActionDispatch::Http::UploadedFile:0x007f3f4946c258>"):
app/controllers/customers_controller.rb:47:in `create'
由CustomerController处理#创建为HTML
参数:{“客户”=>{“名称”=>“测试”、“地址”=>“测试”、“附属机构id”=>“测试”、“类别”=>“,“域”=>”test@web.com“,”电话“=>”1111111“,”联系人“=>”1214521“,”电子邮件“=>”test@malibu.com“,“评论”=>“无”,“徽标”=>“#”,“文件”=>“#”}
参数:
客户:#
控制员:客户
行动:创建
在10毫秒内完成500个内部服务器错误(ActiveRecord:1.0毫秒)
回形针::AdapterRegistry::NoHandlerError(未找到“#”)的处理程序:
app/controllers/customers\u controller.rb:47:in'create'
提前谢谢
客户表单的步骤1包含客户详细信息,步骤2包含主题选择。但是,我能够在步骤1中上载和保存数据,但在主题选择器页面上同时保存步骤1和步骤2中的数据时出现错误
customer.rb
class Customer < ApplicationRecord
has_attached_file :logo
validates_attachment_content_type :logo, :content_type => /\Aimage\/.*\Z/
has_attached_file :file
validates_attachment_content_type :file, :content_type => "application/pdf"
end
class客户/\Aimage\/.\Z/
是否已附加文件:文件
验证\u附件\u内容\u类型:文件,:内容\u类型=>“应用程序/pdf”
结束
你能发布你的model.rb代码吗?@jith谢谢你的快速回复,我也发布了customer.rd