My chap_three_controller.rb file :
class ChapThreeController < ApplicationController
def create
@marker = Marker.new(params[:m])
if @marker.save
res={:success=>true,:content=>"<div><strong>found </strong>#{marker.found}
</div><div><strong>left </strong>#{marker.left}</div>"}
else
res={:success=>false,:content=>"Could not save the marker"}
end
render :text=>res.to_json
end
end
My routes.rb file
match '/map3', :to => 'chap_three#map'
match '/map3/create', :to => 'chap_three#:action'
Am I doing it right matching the create function in the controller to my routes? Because it isn't working..
This is a snippet of my javascript code:
request.open('GET', 'create' + getVars, true);
request.onreadystatechange = function() {
if (request.readyState == 4) {
//the request is complete
var success=false;
var content='Error contacting web service';
try {
//parse the result to JSON (simply by eval-ing it)
res=eval( "(" + request.responseText + ")" );
content=res.content;
success=res.success;
}catch (e){
success=false;
}
The error I keep getting is 'Error contacting web service'. This means that my request.responseText isn't working and the create method in my controller isn't doing anything....Any help would be great