2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Railsでremote:trueの有無でレスポンスの出し分けをしたい

Posted at

利用シーン

= form_tag "/comments", method: :post, remote: true do
  = text_field_tag "body"
  = submit_tag "送信"

# 処理後、Ajax的動作をしたい(jsでalertとか)
= form_tag "/comments", method: :post do
  = text_field_tag "body"
  = submit_tag "送信"

# 処理後、ページ遷移したい
class OpinionsController < ApplicationController

  def create
    # 処理とかいろいろ

    respond_to do |format|
      format.js
      format.html { redirect_to "/home" }
    end
  end

end

remote: true の場合はformat.jsで返せる。

remote: true の時点で気づくべきだったかもだが、すぐに思いつかなかったのでメモ。

2
2
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
2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?