Reputation: 747
I am uploading image using filedrop.js. Code in application.js file looks like this:-
$(".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"
})
}
This part is working fine. I am getting into the proper action with proper parameters.
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
end
upload_file.js.erb:
$("#<%= @custom_game%>_file").html(<%= @custom_game.file%>);
But in view of respective action i.e. upload_file.js.erb I am not able to execute any of the javascript commands , whereas ruby commands are working properly. And in log also it says that the partial has been successfully rendered.
My log shows:-
(101.8ms) COMMIT
Rendered activities/upload_file.js.erb (0.6ms)
Completed 200 OK in 379ms (Views: 10.8ms | ActiveRecord: 106.9ms)
I have no clue where I am making the mistake. No jquery command is being executed in upload_file.js.erb , but ruby commands are working properly.
Upvotes: 0
Views: 450
Reputation: 1406
$("#<%= @custom_game%>_file").html(<%= @custom_game.file%>);
<%= @custom_game %>
returns the CustomGame object, where I think you ment to use @custom_game.title or something.
jQuery cant find $("#<#CustomGame:834793746>_file") so html is not replaced.
You might want to try the javascript in a console to check if it executes manually (using chrome's dev tools myself)
Upvotes: 1