简体   繁体   中英

RoR - Upload JSON render

I have a "Rule list" on "localhost:3000/rules" and its JSON render on "localhost:3000/rules.json"

I want to creat the action "Publish" to upload this json to my FTP but I don't find the solution to make this with Net:FTP.

Here's my code : rules_controller.rb

def publish
   require 'net/ftp'
   ftp = Net::FTP.new('xxxxxx', 'xxxxxxxx', 'xxxxxxx')
   ftp.chdir('www/lol')
   ftp.putbinaryfile('rules.json')
   ftp.close
end

Thanks in advance

Never worked on this but looking at [ http://stdlib.rubyonrails.org/libdoc/net/ftp/rdoc/classes/Net/FTP.html ] It seems ftp.login part is missing.

Well, if you dont need to be authenticated, then need some more insight to give any suggestion. Can you post the problem that you are facing exactly?


Edit:

If you can have your json data (containing all the rules) in a file(like you said rules.json ), this net/ftp should work. Now if you are facing problem with saving the json content in a temporary file, this post - " File.open, write and save? " might help. But if you feel that the problem lies completely in net/ftp , then a error log or more detail description of the problem would be helpful.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM