post '/users/create' do
RestClient.post("http://localhost:3000/users", :user=>params['user'],
:avatar=>File.read("/home/qwerty1/Desktop/client/views/images.jpeg"),
:multipart=>true)
redirect '/users'
end
post '/users/create' do
RestClient.post("http://localhost:3000/users", :user=>params['user'],
:avatar=>File.read("/home/qwerty1/Desktop/client/views/images.jpeg"),
:multipart=>true)
redirect '/users'
end
---------------------------------------
require 'paperclip'
class User < ActiveRecord::Base
has_attached_file :avatar, :styles=>{:thumb=>"100x100",
:medium=>"200x200"}
# validates_attachment_presence :avatar
end
but id didn't sent any image to server
Am I doing something wrong ?
Did you try setting a breakpoint in your rails app to see that the
image was being received properly. Does paperclip expect the name of
the uploaded file (which you aren't currently transmitting) to have an
acceptable extension or for the content type to be set ?
#POST create
post '/users/create' do
f = File.new("temp#{params[:user][:login]}.jpg", "w")
t = params[:avatar][:tempfile]
while c = t.gets do
f.puts(c)
end
f.close
RestClient.post("http://localhost:3000/users",:user=>\{
:login=>params[:user][:login],
:email=>params[:user][:email],
:name=>params[:user][:name],
:avatar=>File.new("temp#{params[:user][:login]}.jpg")},
:multipart=>true)
File.delete("temp#{params[:user][:login]}.jpg")
redirect '/users'
end