save images using paperclip without view

890 views
Skip to first unread message

kashif ali

unread,
May 10, 2013, 12:44:01 PM5/10/13
to papercli...@googlegroups.com
I'm using Paperclip to save images from my current local app directory. I have used two models to save images. 

business.rb   

    class Business < ActiveRecord::Base
    # Associations
       has_attached_file :logo, :styles => {:thumb => "100x100>"}
       validates_attachment :logo,
                       :size => {:in => 1..1500.kilobytes}
    end

image.rb

    class Image < ActiveRecord::Base
       has_attached_file :data, :styles => { :thumb => '100x100>', :medium => '240x240>' }
    end

when i try to save image it is not working for me like below.

    Business.create(:logo => Image.first.url)

and i have this error

    Paperclip::AdapterRegistry::NoHandlerError: No handler found for "/system/images/data/000/000/177/medium/error.png"

while "Image.first.url" give me this path

       "/system/images/data/000/000/177/medium/error.png"

How i can do this?

Thanks


Andrés gutiérrez

unread,
May 11, 2013, 6:07:23 AM5/11/13
to papercli...@googlegroups.com

Why do you need 2 papeeclip fields? You could make a relation bewteen image and business

business.logo = image

--
--
Individuals over processes. Interactions over tools.
 
Agile Rails training from thoughtbot, the makers of Paperclip, Clearance, Shoulda, & Factory Girl:
http://thoughtbot.com/services/training
 
The Paperclip group:
http://groups.google.com/group/paperclip-plugin
 
To post to this group, send email to
papercli...@googlegroups.com
 
To unsubscribe from this group, send email to
paperclip-plug...@googlegroups.com
---
You received this message because you are subscribed to the Google Groups "Paperclip Plugin" group.
To unsubscribe from this group and stop receiving emails from it, send an email to paperclip-plug...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

kashif ali

unread,
May 14, 2013, 6:13:06 AM5/14/13
to papercli...@googlegroups.com
I have association like this

     business.rb

       has_many :images

    image.rb

       belongs_to :business

so on my business new page user can upload many images. while on edit page all images against one business will be display and when user click on any image it becomes logo for business.

       so on edit action in controller

    def edit

      @business = Business.find(params[:id])

      @business.update_attribute(:logo ,@business.images.first.url)
 
   end

i have this error


 how i can save or update this image as logo.

Thanks       

Andrés gutiérrez

unread,
May 14, 2013, 6:32:57 AM5/14/13
to papercli...@googlegroups.com
Maybe :logo is expecting a Paperclip object and you are passing a String.

Try:
@business.update_attribute(:logo ,@business.images.first)


2013/5/14 kashif ali <kashif....@gmail.com>
Reply all
Reply to author
Forward
0 new messages