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 8852245
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T13:21:04+00:00 2026-06-14T13:21:04+00:00

I am currently trying to display a message every time a custom method (process!)

  • 0

I am currently trying to display a message every time a custom method (process!) returns either false or true within my transaction controller. However, it is only returned once for every false and once for every true. Below is the code in the controller:

 def execute_all
@transaction = Transaction.find(:all)
#Execute all transactions
@transaction.each do |t|
        if (t.process!)
            #flash.keep[:noticeTransaction] = 'Transaction number: ' + t.id.to_s + ' executed Successfully!'
            else 
            flash.keep[:errorTransaction] = 'Transaction cannot be executed -> Transaction Id: ' + t.id.to_s
        end
        end
respond_to do |format|
      format.html { redirect_to transactions_url }
      format.json { head :no_content }
    end

Below is the code in the application.html.erb

<html>
<head>

</head>
<body>
<p style="color:red" class="error"><%= flash[:errorTransaction] %></p>
<p style="color:green" ><%= flash[:noticeTransaction] %></p>

<%= yield %>

</body>

I assuming since I only mention it once in the application layout (one for error and one for success) it display it only once. I am wondering how would I have it to display for each false that is returned by the method “process!”.

Thanks in advance.

  • 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-14T13:21:05+00:00Added an answer on June 14, 2026 at 1:21 pm

    The layout displays only one, because there is only one. flash stores one message per key, regardless of whether you use keep or not.

    So each time you set flash.keep[:errorTransaction], you’re overwriting the previous message, not appending another one.

    To solve this you could store all the messages as you iterate over the transactions, then store them on the flash all at once, something like:

    messages = []
    @transaction.each do |t|
      if (t.process!)
        messages << '<div class="some-class">your message in a wrapper</div>'
      end
    end
    flash.keep[:errorTransaction] = messages.join if messages.any?
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am currently trying to create a statement where if it returns false then
I am currently trying to print a message from a child process after calling
Trying to display current time with PHP (using this ): $date = date('m/d/Y h:i:s
I'm currently trying to set up a secured folder with a few pages within
I am currently trying to specify custom error messages in grails for the default
I am currently using phonegap and trying to display results from a sqlite table
I'm currently trying simple validation using required=true <h:form> <h:messages globalOnly=true/> <h:panelGrid> <h:panelGrid columns=3> <f:facet
I'm trying to display a spanish price. Spanish prices have the currency symbol AFTER
For debug purposes, I'm trying to display the current content inside a foreach loop
Currently trying at add ajax to a site, after much reading I discovered that

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.