Reputation: 5619
in my Rails app i've got the carrierwave gem to upload stuff. Now I want a validation of fileformats
so I've added this in uploader:
def extension_white_list
%w(jpg jpeg gif png)
end
When I try to upload a pdf it dosn't upload the pdf but no error is printed to screen. What is missing?
I think the page should go back so the user has the oportunity to select a different file ?
Thanks
UPDATE - Form View Code:
<%= 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>
UPDATE: Controller function
#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
Upvotes: 0
Views: 93
Reputation: 10406
So essentially you're not outputting errors, so using the format from the guides you need to add:
<% 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 %>
Upvotes: 1