5

I need to upload image to my filme collection application i use carrierwave to do this (follows the railscasts steps)

step 1 i add gem 'carrierwave', '~> 0.9' to my Gemfile then run bundle step 2 rails g uploader image then rails g scaffold filmes name moviestype after rake db step 3 rails g migration add_image_to_filmes image:string and then rake db

other step are same as railscasts

in my filme modle

attr_accessible :name, :moviestype, :image
  mount_uploader :image, ImageUploader

in my _form.html.erb

<%= form_for @filme, :html => {:multipart => true} do |f| %>
  <% if @filme.errors.any? %>
    <div id="error_explanation">
      <h2><%= pluralize(@filme.errors.count, "error") %> prohibited this filme from being saved:</h2>

      <ul>
      <% @filme.errors.full_messages.each do |msg| %>
        <li><%= msg %></li>
      <% end %>
      </ul>
    </div>
  <% end %>

  <div class="field">
    <%= f.label :name %><br>
    <%= f.text_field :name %>
  </div>
  <div class="field">
    <%= f.label :moviestype %><br>
    <%= f.text_field :moviestype %>
  </div>
  <div class="field">
   <br>
    <%= f.file_field :image %>
  </div>

  <div class="actions">
    <%= f.submit %>
  </div>
<% end %>

in show.html.erb

<p id="notice"><%= notice %></p>

<p>
  <strong>Name:</strong>
  <%= @filme.name %>
</p>

<p>
  <strong>Moviestype:</strong>
  <%= @filme.moviestype %>
</p>
<%= image_tag @filme.image_url(:thumb) if @filme.image? %>

<%= link_to 'Edit', edit_filme_path(@filme) %> |
<%= link_to 'Back', filmes_path %>

problem is it didn't upload any image but film name and other fields are inserting to db.how can i fix this ?need quick help.

Kirti Thorat
  • 52,578
  • 9
  • 101
  • 108
Nuwan Indika
  • 901
  • 4
  • 14
  • 27
  • Please share the server log generated upon submitting the form. – Kirti Thorat Apr 08 '14 at 14:10
  • https://www.dropbox.com/s/zxtoh9olabn4jzy/log.txt – Nuwan Indika Apr 08 '14 at 14:18
  • Have you got :image white-listed? Do you have a method in your controller that specifies what can be uploaded? Might look like this... params.require(:filme).permit(:name, :moviestype) ... in qhich case you need to add :image (and :image_cache, eventually) – SteveTurczyn Apr 08 '14 at 14:19

1 Answers1

4

As per the error logs, you have not permitted image to be saved in the database. In your FilmesController, you need to permit :image as

def filme_params
  params.require(:filme).permit(:name, :moviestype, :image) ## Add :image attribute
end
Kirti Thorat
  • 52,578
  • 9
  • 101
  • 108
  • this my controller https://www.dropbox.com/s/ih54m4pk6y9vsfz/filmes_controller.rb – Nuwan Indika Apr 08 '14 at 14:24
  • @KirtiThorat Its better to use this `params.fetch(:fileme, {})` [link](http://stackoverflow.com/questions/17937112/rails-4-strong-parameters-param-not-found-error-with-carrierwave/18040556#18040556) – Viren Apr 16 '14 at 15:32