我正在使用filedrop.js上传图像。application.js文件中的代码如下所示:
$(".droparea").each(function(event){
var game_id = $(this).attr('id')
$(this).filedrop({
maxfilezsize: 5,
maxfiles: 1,
dataType: "script",
paraname :"custom_game[file]"
url: "/game_plans/'+$(".dropbox").attr("rel")+'/games/'+game_id+/upload_file.js"
})
}这部分运行得很好。我正在使用适当的参数进行适当的操作。
def upload_file
# NOTE Upload_file action has been explicity written for the file upload using drag and drop
@custom_game = CustomGame.find_or_initialize_by_id(params[:id])
@game_plan = GamePlan.find(params[:game_plan_id])
@custom_game.update_attributes(params[:custom_game])
respond_to do |format|
format.js
end
endupload_file.js.erb:
$("#<%= @custom_game%>_file").html(<%= @custom_game.file%>);但是考虑到相应的操作,即upload_file.js.erb,我不能执行任何javascript命令,而ruby命令工作正常。在log中,它还表示已成功呈现部分。
我的日志显示:
(101.8ms) COMMIT
Rendered activities/upload_file.js.erb (0.6ms)
Completed 200 OK in 379ms (Views: 10.8ms | ActiveRecord: 106.9ms)我不知道我在哪里犯了错。在upload_file.js.erb中没有执行任何jquery命令,但是ruby命令工作正常。
发布于 2012-06-26 22:26:00
$("#<%= @custom_game%>_file").html(<%= @custom_game.file%>);<%= @custom_game %>返回CustomGame对象,我认为您应该在其中使用@custom_game.title或其他什么。jQuery找不到$("#<#CustomGame:834793746>_file"),所以html不会被替换。
您可能希望在控制台中尝试javascript,以检查它是否手动执行(我自己使用chrome的开发工具)。
https://stackoverflow.com/questions/11201681
复制相似问题