LoginSignup
3
1

More than 5 years have passed since last update.

RailsでAjax呼び出し時にリダリレクする方法

Posted at

例えば、loginしていなかったらlogin画面に遷移する場合。

def check_login
    unless login?
        render js: "window.location = '#{login_path}'"
    end
end

check_login.js.erbを用意して、そのjsファイルないで以下をおこなってもよいですが、上記のように直接指定してもOKです。

check_login.js.erb
<% unless login? %>
window.location = '<%= login_path %>'
<% end %>
3
1
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
3
1