LoginSignup
16
10

More than 5 years have passed since last update.

JSで返す時に ActionController::UnknownFormat がでたら

Last updated at Posted at 2015-10-19

ActionController::UnknownFormat

コントローラーにアクセスしてくるリクエストのフォーマットと、コントローラーが待ち受けてるフォーマットが合っていない時に発生する。

コントローラー

Ajaxアクセス予定だったので、こんな風に書いてた。
(format.jsしか待ち構えてない)

def create
  # ...
  respond_to do |format|
    if @comment.save
      format.js
    end
  end
end

間違いビュー

= simple_form_for [ @topic, @topic.comments.new ] do |f|
  = f.input :comment
  = f.button :submit, 'コメント投稿', class: "btn btn-primary"

remote: true し忘れてるので、htmlフォーマットを要求している状態。

正しいビュー

= simple_form_for [ @topic, @topic.comments.new ], remote: true do |f|
  = f.input :comment
  = f.button :submit, 'コメント投稿', class: "btn btn-primary"

ぐぬぬ・・こんなことで・・ハマるとは;;

16
10
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
16
10