No route matches "/sessions.json

469 views Asked by At

So why would I be getting this error and why its pointing to localhost instead of localhost:3000?

Completed in 27ms (View: 3, DB: 13) | 406 Not Acceptable [http://localhost/sessions.json]

I am trying to use ObjectiveResource (iphone app) and Rails. ObjectiveResource points to sessions.json with a Post I guess when creating a session.

In my routes file I am using

map.resources :sessions map.connect ':controller.:format'
map.connect ':controller/:action.:format'

2

There are 2 answers

0
thenengah On BEST ANSWER

in your routes.rb you only need this:

map.resources :sessions

Your path is correct but you need responds_to block in the action

def create
    Session.create(params[:session])
    responds_to do |format|
        format.json 
    end 
end 
0
Fernando Diaz Garrido On

You need to register json as a Mime Type. Check that in the file app_root/config/initializers/mime_types.rb you have a line like:

Mime::Type.register_alias "application/json", :json