Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

respond_with returns unknown format - rails

I am using through AngularJS to send some json, in the controller I have

respond_to :json

def create
    respond_with Task.create(description: params[:description])
end

the tasks is stored on the database, but then I get this message in my log

ActionController::UnknownFormat - ActionController::UnknownFormat:
  (gem) actionpack-4.0.0/lib/action_controller/metal/mime_responds.rb:372:in `retrieve_collector_from_mimes'
  (gem) actionpack-4.0.0/lib/action_controller/metal/mime_responds.rb:327:in `respond_with'

...

I tried to add in my route resources :tasks, :defaults => {:format => "js"}. How can I handle this problem ?

like image 508
user1611830 Avatar asked Dec 26 '13 16:12

user1611830


1 Answers

You want your default format to be "json", not "js".

Rails has a list of formats that it is expecting (based on defaults plus you or gems can add additional known response types.) Js is not one of the defaults

like image 138
Chris Avatar answered Sep 28 '22 09:09

Chris