Forum: Ruby on Rails Routing error in ajax on ruby on rails

2eed0dd2deef77f8d132501d1e8e28ea?d=identicon&s=25 Jose Urquidi (urcoconc)
on 2013-10-02 21:29
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?
5f94b9b346c2aa648a80bc259978e5bc?d=identicon&s=25 Colin Law (Guest)
on 2013-10-02 22:39
(Received via mailing list)
On 2 October 2013 20:29, Jose Urquidi <lists@ruby-forum.com> 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
Please log in before posting. Registration is free and takes only a minute.
Existing account

NEW: Do you have a Google/GoogleMail, Yahoo or Facebook account? No registration required!
Log in with Google account | Log in with Yahoo account | Log in with Facebook account
No account? Register here.