rails paperclip: uploaded file does not get stored
I am making my first steps with the Rails plugin 'paperclip' an therefor watched the RailsCast #134: http://railscasts.com/episodes/134-paperclip
Did everthing the same, except that I'm running rails 3.0.9 and installed paperclip (2.3.15) via adding it to the Gemfile.
Until 3:00 of the cast, everything works fine. But after reloading the show-page, I get the "missing" image instead of the uploaded image. Also, inside of the 'public' directory nothing new has been created.
Any hints?
Update: As req开发者_C百科uested here the relevant code:
Gemfile:
…
gem 'paperclip'
gem 'rails', '3.0.9'
…
config/routes.rb:
Foobar::Application.routes.draw do
resources :books
end
app/models/book.rb:
class Book < ActiveRecord::Base
has_attached_file :cover
attr_accessor :cover_file_name
end
app/controllers/books_controller.rb:
# nothing changed here after scaffolding
app/views/books/_form.html.erb:
<%= form_for(@book, :html => { :multipart => true}) do |f| %>
…
<div class="field">
<%= f.file_field :cover %>
</div>
app/views/books/show.html.erb:
…
<%= image_tag «book.cover.url %>
…
db/migrate/..._create_books.rb:
class CreateBooks < ActiveRecord::Migration
def self.up
create_table :books do |t|
t.string :name
t.timestamps
end
end
def self.down
drop_table :books
end
end
db/migrate/..._ad_attachment_cover_to_book.rb:
class AddAttachmentCoverToBook < ActiveRecord::Migration
def self.up
add_column :books, :cover_file_name, :string
add_column :books, :cover_content_type, :string
add_column :books, :cover_file_size, :integer
add_column :books, :cover_updated_at, :datetime
end
def self.down
remove_column :books, :cover_file_name
remove_column :books, :cover_content_type
remove_column :books, :cover_file_size
remove_column :books, :cover_updated_at
end
end
I started up with "rails generate paperclip book cover" after having scaffold "book"
I think that the attr_accessor :cover_file_name
creates a conflict for the table column with the same name. Try removing that line. Can't find anything else that should cause any problems.
People I think I already gave the solution when you appear this error is because the cover column does not have permission to enter this is solved in the controller of articles in the params_article can only manipulate the title and the body to this also adds to it To the column cover to me I stay like this
Def articulo_params params.require (: article) .permit (: title,: body,: cover)
End
精彩评论