Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rails 5.1 redirect_to flash issue #30207

Closed
elquimista opened this issue Aug 12, 2017 · 2 comments
Closed

Rails 5.1 redirect_to flash issue #30207

elquimista opened this issue Aug 12, 2017 · 2 comments

Comments

@elquimista
Copy link

Steps to reproduce

users_controller.rb

class UsersController < ApplicationController
  def update
    if @user.update(user_params)
      redirect_to action: 'show', notice: 'User saved!'
    end
  end
end

application.html.slim

- if notice.present?
  .message= notice

Expected behavior

After successful update on User model, it should redirect to show and display flash[:notice] (or just notice).

Actual behavior

Redirect works fine, but flash does not show up. Instead, browser url bar has some GET style querystring, e.g., localhost:3000/users?notice=User+saved%21

However, if I set flash in separate line (e.g., flash[:notice] = 'User saved!') and remove notice param in redirect_to, flash notice displays properly.

System configuration

Rails version: 5.1.2

Ruby version: 2.4.1p111

@y-yagi
Copy link
Member

y-yagi commented Aug 12, 2017

Action and flash need to be passed separately. Like following:

def update
  if @user.update(user_params)
    redirect_to({ action: 'show'}, notice: 'User saved!')
  end
end

Otherwise flash is considered an option for the URL.

Ref: http://api.rubyonrails.org/classes/ActionController/Redirecting.html#method-i-redirect_to

@elquimista
Copy link
Author

Ah I see. Didn't notice about that before. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants