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

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
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
This topic is locked and can not be replied to.