How can I save a photo without sending a form, rails

If I already have a photo in my file system, how can I save it without submitting a form? I would like to do this in the controller when some action happens.

I use paperclip to save my photos. therefore, if you have an idea how to make paperclip save it, it will also be very useful.

Clip:

I already have a photo saved with a paper clip. This photo belongs to the horse (model). What I want to do is when a new horse is created, gives that horse the same photo. so how can i do that. I tried to point to this photo with a paper clip. I just copied the attributes of the original photo. he does not work. paperclip looks in the wrong folder.

So, I have a model. he belongs to a horse model. Four attributes are required using paperclip: data_content_type, data_file_name, data_file_size, data_updated_at.

If I then create a new instance of the class photo with Photo.new and give it four clip parameters, paperclip looks for another place where the file is saved.

What can I do? How can I save it in the controller without submitting the form? (with a folder (preferably) or without)

thanks for any answers

+3
source share
3 answers

I don’t quite understand how you made the previous attempt, but this is what I do to assign photos to the model object:

horse.photo = File.open("path/to/image/NameOfFile.extension")
horse.save!
+6
source

paperclip default_url? , . , , .

has_attached_file :avatar, 
                  :styles => { :thumb => "48x48#" },
                  :default_url => "/images/avatars/missing_avatar.png",
                  :default_style => :thumb
+1

Flash ( ), AJAX. : SWFUpload Uploadify. , , Rails GitHub

-2

Source: https://habr.com/ru/post/1751298/


All Articles