內使用javascript軌道創建我有在我創建外部events.json文件軌這種方法的文件。如何閱讀new.html.erb
def new
@event=Event.new
@users=User.all
@[email protected]
tempJson = @events.to_json.html_safe
aFile = File.new("events.json", "r+")
aFile.syswrite(tempJson)
end
現在events.json文件在我的app目錄中創建。 在我new.html.erb,如何通過JavaScript訪問該文件,並將其設置爲一個變量?
<script type="text/javascript">
$.getJSON("events.json", function(json) {
debugger;
console.log(json);
});
</script>
我想這個..當我檢查我收到此錯誤信息,
Failed to load resource: the server responded with a status of 404 (Not Found) http://localhost:3000/users/14/events/events.json
爲什麼不把它渲染爲json的方法? – webster
文件存儲位置的實際路徑是什麼?即它在哪個目錄中? – user2085143
@ user2085143的events.json文件生成並存儲相同的應用程序目錄,其中的應用程序,bin等等目錄存在[畫面]內(https://drive.google.com/open?id=0B2BZFbohNopKT1FIOTlpNi1hVEE) –