LoginSignup
13
12

More than 5 years have passed since last update.

Rails responseにrenderでjsファイルを返すには

Posted at

render js: 'ファイル名'とかやって無駄に時間を費やした自分向けのメモです。

NGケース

class CommandsController < ApplicationController
  def create
    # command_result.js.erbが読まれると期待しても、クライアントへの応答は'command_result'という文字列
    render js: 'command_result'
  end
end

OKケース

class CommandsController < ApplicationController
  def create
    # command_result.jsやcommand_result.coffeeの内容を、クライアントへ返す
    render 'command_result'
  end
end
13
12
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
13
12