简体   繁体   中英

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 ?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM