Rails 4 + -jquery-datatable + ajax-datatable - Error 406 Http and ActionController :: UnknownFormat format json

0

I was studying rails and following the link tutorial.

The steps in the tutorial were as follows, create a datatable that would make a request via json, the controller that would respond with the data and the data table would be populated.

At the time of the test I received the following server error: 406 Not Acceptable, and detailing the chrome error in the network tab, the following error is displayed:

ActionController :: UnknownFormat at /categories.json%20

  

ActionController :: UnknownFormat

app / controllers / categories_controller.rb, line 8

'' 'ruby     3 before_action: set_category, only: [: show,: edit,: update,: destroy]     4
    5 # GET / categories     6 # GET /categories.json     7 def index

  

8 respond_to do | format |       9 format.html      10 format.json {render json: CategoryDatatable.new (view_context)}      11 end      12 end      13   '' '

I searched but could not find or find a solution.

The following is a step-by-step guide to the code if someone can help me:

View:

Coffe:Responsibleforupdatingthedatatablewhencalledbytheview

Controller-indexmethod:

Browsererror:AbaNetwork:

Detailedbrowsererror:

Inotherwords,theserverIunderstooddidnotacceptthecallviajson,butIdidnotknowhowtoacceptit.ThetutorialsorsimilarerrorsIfoundareinthesamewayandastheauthorswork.

IfImaketherequestdirectlyinthebrowser link the file is displayed without problems: {"draw": 0, "recordsTotal": 3, "recordsFiltered": 3, "data": [[1, "Test1", "Error", "Yes" "Error", "No")]]

If anyone can help me, I'll be grateful.

    
asked by anonymous 15.09.2015 / 01:12

1 answer

1

The error is indicating that the rails does not recognize the format used in the request.

In the view the value of the data-source attribute has a space after the url, so the request made by the DataTable is link space and rails is trying to render the .json space format

Just remove the space at the end of the data-source value.

    
15.09.2015 / 02:21