Reputation: 4188
I'm a newbies to the rails world . What I'm trying to do is to add the abilities to user to add picture . I did some reaserch and, I found a gem called "paperclip",but after installing. Every time I try to upload a picture, I get "no file selected".
this is my models
attr_accessible :description, :image
validates :description, presence: true
validates :user_id, presence: true
belongs_to :user
has_attached_file :image , :styles => { :small => "150x150>" }
validates_attachment :image , :presence => true,
:content_type => { :content_type => ["image/jpeg", "image/jpg","image/png","image/gif"] },
:size => { :in => 0..10.kilobytes }
and this is my views
<div class="form-inputs">
<%= f.input :image , label: "upload a picture !! " %>
<%= f.input :description , as: :text ,input_html: { rows:"3"} %>
Upvotes: 0
Views: 770
Reputation: 7941
Step by Step
Gem
gem "paperclip", "~> 3.0"
Terminal
$ bundle install
$ rails generate paperclip user image
$ rake db:migrate
User model
class User < ActiveRecord::Base
attr_accessible:image, :description
validates :description, presence: true
validates :user_id, presence: true
has_attached_file :image, styles: { medium: "320x240>"}
validates_attachment :image, presence: true,
content_type: { content_type: ['image/jpeg', 'image/jpg', 'image/png', 'image/gif'] },
size: { less_than: 5.megabytes } # you wanna change that
belongs_to :user
end
Your View is ok, don't forget to rake db:migrate
and restart your Server
Upvotes: 1