0
现在我试图在注册时为用户下载一个随机头像。 所以我得到机械化,并在研究后做到这一点。Rails:通过机械化自定义文件名下载
class RegistrationsController < Devise::RegistrationsController
def new
super
end
def create
agent = Mechanize.new
agent.pluggable_parser.default = Mechanize::Download
f = agent.get('http://avatar.3sd.me/100')
f.save('public/images/avatar/it_should_be_user_id.png')
super
end
def update
super
end
end
但我无法弄清楚如何根据用户ID文件保存在特定的名称,该怎么办呢?
非常感谢, 它做的工作 – user3759996
我很高兴它。你介意接受这个答案作为最好的答案吗? – gitcdn