Routing error in ajax on ruby on rails

I have this in my .html.erb code:

$.ajax({
url: “/timeMachineEdit”,
data: {editTimeMachine: newArray},
type: ‘POST’,
success: function (res) {
if (res.result === ‘ok’) {
alert(‘Data saved’);
} else {
alert(‘Save error’);
}
},
error: function () {
alert(‘Save error.’);
}
});

This in my datasets_controller.rb

def timeMachineEdit
@dataset = current_user.dataset
@dataset.machine_time = params[:editTimeMachine]
end

And in my routes.rb:

match “/timeMachineEdit”, to: “datasets#timeMachineEdit”

But when is submited shows:

POST http://localhost:3000/timeMachineEdit 500 (Internal Server Error)

Where is the problem here? is the routes in the ajax url or something
else?

On 2 October 2013 20:29, Jose U. [email protected] wrote:

 alert('Save error');

def timeMachineEdit
But when is submited shows:

POST http://localhost:3000/timeMachineEdit 500 (Internal Server Error)

Where is the problem here? is the routes in the ajax url or something
else?

rake routes will show you the routes that are valid. If you try that
I expect you will see that timeMachineEdit is only routed for GET.
You need to specify specifically if you want it to be valid for POST.
See the Rails Guide on Routing for more information.

Colin

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs