Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9222459
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T03:50:22+00:00 2026-06-18T03:50:22+00:00

Why does Rails flash[:notice] =msg work where :notice => msg doesn’t? The notice displays

  • 0

Why does Rails flash[:notice] =”msg” work where :notice => “msg” doesn’t? The notice displays if I use the following code:

# Case 1 (this works)
flash[:notice] = 'Candidate was successfully registered.'
format.html { redirect_to :action => "show_matches", :id => @trial.id }

This does not work:

# Case 2 (this doesn't)
format.html { redirect_to :action => "show_matches", :id => @trial.id, :notice => "Candidate was successfully registered."}

But in other areas of my application, the above technique works just fine:

# Case 3 (this works)
format.html { redirect_to @candidate, :notice => 'Candidate was successfully created.' }

My layout includes:

<section id="middle_content">
    <% flash.each do |key, value| -%>
        <div id="info_messages" class="flash <%= key %>"><%= value %></div>
        <br/>
    <% end -%>
    <%= yield -%>
</section>

So my question is why does using :notice => "" work in one case but not the other?

I realize I have not given you much context, but my sense is that my issue is actually very simple.

p.s. This seems similar to this question.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T03:50:23+00:00Added an answer on June 18, 2026 at 3:50 am

    The redirect_to method takes two arguments according to the documentation

    The second argument is where the :notice key is to be put.

    However, in your Case 2, ruby can’t tell if there is one or more hashes involved. Only one hash is considered to be passed to the redirect_to method.

    You can force ruby to pass a second hash by explicitly setting brackets around each hash :

    format.html { redirect_to({:action => "show_matches", :id => @trial.id}, {:notice => "Candidate was successfully registered."}) }
    

    The case 3 works because there is no ambiguous hash situation here.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This method works on my local machine but does not work on my remote
Hi I ran in this issue a while ago... authlogic flash[:notice] does not show
Why does my flash[:notice] appear permanently on the redirected page? - Rails 3.1 In
I have this code : def create login(params[:email], params[:password]) if current_user flash[:notice] = Welcome
Does Ruby (or Rails) provide an easy way to accomplish the following: if @author.articles.each(:published
Does anybody know how to create a rails application that use noSql database? We
I want to render my Rails flash[:notice] and flash[:error] messages in a bar at
Im using twitter-bootstrap in my rails app i was following this tutorial : http://untame.net/2012/08/twitter-bootstrap-build-a-stunning-two-column-blog/
I have a rails app, for some reason my login action does not work.
I'm working with Rails 3.2.8 and am running jQuery v1.8.2. The following works: $(window).load(function(){

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.