我想在控制器中进行ajax调用并获得结果时执行ruby脚本。 但是我的ajax调用仍然有错误500 ...
file.js
$.post("/script/scraping", { "url" : url }, function(data) {
console.log(data);
});
/script/scraping.rb
puts "test"
/config/routes.rb
post "/scraping", :to "scraping#run_script"
/app/controller/scraping_controller.rb
class ScrapingController < ApplicationController
def run_script
@results = `ruby /script/scraping.rb`
end
end
修改
好吧,我修好了。问题是渲染/刮擦路径。响应丢失了模板错误,然后我只是添加到我的操作
render :text => @results