Rails 4 - Paperclip does not display uploaded images -
i learning rails, , next along mattan griffel's 'one mont rails.' have spent lot of time looking reply , have tried everything, nil seems work. using paperclip gem, upload images, after upload, images not displayed. thing displayed, missing images icon. please help. give thanks much.
here link github repo: github.com/robertguss/omrails
pins controller: pins_controller.rb
class pinscontroller < applicationcontroller respond_to :html, :xml, :json before_filter :authenticate_user!, except: [:index] before_action :set_pin, only: [:show, :edit, :update, :destroy] def index @pins = pin.all respond_with(@pins) end def show respond_with(@pin) end def new @pin = current_user.pins.new respond_with(@pin) end def edit @pin = current_user.pins.find(params[:id]) end def create @pin = current_user.pins.new(pin_params) @pin.save respond_with(@pin) flash[:success] = "pin created successfully!" end def update @pin = current_user.pins.find(params[:id]) @pin.update(pin_params) respond_with(@pin) flash[:success] = "pin updated successfully!" end def destroy @pin = current_user.pins.find(params[:id]) @pin.destroy respond_with(@pin) flash[:alert] = "pin deleted!" end private def set_pin @pin = pin.find(params[:id]) end def pin_params params.require(:pin).permit(:description) end end
pins model = pin.rb
class pin < activerecord::base validates :user_id, presence: true validates :description, presence: true has_attached_file :image, :path => ":rails_root/public/system/:attachment/:id/:style/:filename", :url => "/system/:attachment/:id/:style/:filename" validates_attachment :image, content_type: { content_type: ['image/jpeg', 'image/jpg', 'image/png' 'image/gif'] }, size: { less_than: 5.megabytes } belongs_to :user end
on def pin_params
should add together permission image file; be:
def pin_params params.require(:pin).permit(:description, :image) end
ruby-on-rails-4
No comments:
Post a Comment