I have a button with a click even handler:
score_button_click_handler = (e) ->
$.ajax
url: "/practice_scores/#{practice_score_id}.json",
dataType: "json",
type: "POST",
contentType: "application/json",
processData: false,
data: "{ \"practice_score\": {\"score_id\": #{score_id}, \"practice_id\": #{practice_id} }}",
beforeSend: (xhr) ->
xhr.setRequestHeader("X-Http-Method-Override", "PUT");
success: ->
category_id = $("#category-practices").data("category-id")
assessment_id = $("#viz").data("assessment-id")
render_average assessment_id, category_id
In practice_scores_controller.rb, I have the action:
def update
@practice_score = PracticeScore.find(params[:id])
respond_to do |format|
if @practice_score.update_attributes(params[:practice_score])
format.html { redirect_to questionnaire_path, notice: 'Practice score was successfully updated.' }
format.json {render "update.js.coffee.erb"}
else
format.html { render action: "edit" }
format.json { render json: @practice_score.errors, status: :unprocessable_entity }
end
end
end
In app/views/practice_scores/ is update.js.coffee.erb. It has a simple console log statement in it.
I can't for the life of me get the update view to render. I have also tried the following just to see if I can get it to respond.
format.json {render js: "alert('Something')"}
I'm not seeing any thing in the console or having an alert pop up. Ultimately, I'd like to respond to the request with coffee/js to update my UI. Does it have to do with the POST request? I have scoured the blogs and I seem to be doing things they way they describe, but I'm just not seeing a response.
jsorjson? (because you're asking for the latter, but expecting it to return the former)?.js, datatype to js, etc. to reformat the POST request as a JS call?render js: "console.log('test');", but a MissingTemplate error is being thrown when I just haveformat.jsorformat.js {}.erb.