不显示载波白名单错误
carrierwave whitelist error isn't displayed
在我的 Rails 应用程序中,我使用载波 gem 来上传内容。现在我想要验证文件格式
所以我在上传器中添加了这个:
def extension_white_list
%w(jpg jpeg gif png)
end
当我尝试上传 pdf 时,它没有上传 pdf,但屏幕上没有打印错误。缺少什么?
我认为该页面应该返回以便用户有机会 select 不同的文件?
谢谢
更新 - 表单查看代码:
<%= form_for(@channel, :html => {:multipart => true, :class => "form-horizontal", :role => "form"}, :method => :post, :url => url_for(controller: 'channels', action: 'edit', id: @channel.id)) do |f| %>
<div class="col-md-4">
<div class="form-group col-md-12">
<label><%= f.label :channelimage %></label>
<%= f.file_field :channelimage, :class => "form-control", :placeholder => :image%>
<br>
<% if @channel.channelimage.present? %>
<div clasS="thumbnail">
<img src="<%= @channel.channelimage %>" alt="<%= @channel.channelname %>"/>
</div>
<% end %>
</div>
</div>
更新:控制器功能
#Speichert die geänderten Werte eines Channels
def edit
@user = User.find_by_id session[:user_id]
@knowledgeproviderList = @user.knowledgeprovider
@channel = Channel.find params[:id]
@channelList = Channel.where(knowledgeprovider_id: @knowledgeproviderList.pluck(:id))
if request.post?
@channel.update_attributes(channel_edit_params)
if @channel.save
flash[:notice] = t("flash.saved")
redirect_to action: :index
else
redirect_to action: :edit, :id => @channel.id
end
end
end
所以基本上你没有输出错误,所以使用指南中的格式你需要添加:
<% if @channel.errors.any? %>
<div id="error_explanation">
<h2>
<%= pluralize(@channel.errors.count, "error") %> prohibited
this channel from being saved:
</h2>
<ul>
<% @channel.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
在我的 Rails 应用程序中,我使用载波 gem 来上传内容。现在我想要验证文件格式
所以我在上传器中添加了这个:
def extension_white_list
%w(jpg jpeg gif png)
end
当我尝试上传 pdf 时,它没有上传 pdf,但屏幕上没有打印错误。缺少什么?
我认为该页面应该返回以便用户有机会 select 不同的文件?
谢谢
更新 - 表单查看代码:
<%= form_for(@channel, :html => {:multipart => true, :class => "form-horizontal", :role => "form"}, :method => :post, :url => url_for(controller: 'channels', action: 'edit', id: @channel.id)) do |f| %>
<div class="col-md-4">
<div class="form-group col-md-12">
<label><%= f.label :channelimage %></label>
<%= f.file_field :channelimage, :class => "form-control", :placeholder => :image%>
<br>
<% if @channel.channelimage.present? %>
<div clasS="thumbnail">
<img src="<%= @channel.channelimage %>" alt="<%= @channel.channelname %>"/>
</div>
<% end %>
</div>
</div>
更新:控制器功能
#Speichert die geänderten Werte eines Channels
def edit
@user = User.find_by_id session[:user_id]
@knowledgeproviderList = @user.knowledgeprovider
@channel = Channel.find params[:id]
@channelList = Channel.where(knowledgeprovider_id: @knowledgeproviderList.pluck(:id))
if request.post?
@channel.update_attributes(channel_edit_params)
if @channel.save
flash[:notice] = t("flash.saved")
redirect_to action: :index
else
redirect_to action: :edit, :id => @channel.id
end
end
end
所以基本上你没有输出错误,所以使用指南中的格式你需要添加:
<% if @channel.errors.any? %>
<div id="error_explanation">
<h2>
<%= pluralize(@channel.errors.count, "error") %> prohibited
this channel from being saved:
</h2>
<ul>
<% @channel.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>