Problems getting flash to display

I have a controller that looks exactly like the code below. My problem
is that I can’t get the flash[:notice]'s to show up on the page.
Interestingly though, I when I test this controller, I have tests that
make it go down both of the unhappy paths (the
ActiveRecord::RecordInvalid exception and ‘some_boolean_expression
should’ve been true’) and these tests pass when ‘assert_match’ on the
flash…

assert_match(/Error saving:/, flash[:notice])

and

assert_match(/some_boolean_expression should’ve been true/,
flash[:notice])

respectively

Any thoughts on what could possibly explain the fact I can’t see the
flash in the browser?

TIA…

===== controller code =====

def do_the_action
if (some_boolean_expression)
begin
model = ModelObject.new(:attribute1 => “1”, :attribute2 => “2”)
model.save!

    path = "a/path"
    redirect_to(path)
  rescue ActiveRecord::RecordInvalid => error
    # findme: this flash notice doesn't seem to be showing up;

logging it for now
@@log.error(“Error saving: #{error}”)
flash[:notice] = “Error saving: #{error}”
redirect_to :action => “show”
end
else
# findme: this flash notice doesn’t seem to be showing up; logging
it for now
@@log.error(“some_boolean_expression should’ve been true”)
flash[:notice] = “some_boolean_expression should’ve been true”
redirect_to :action => “show”
end
end

Bryan N. wrote:

I have a controller that looks exactly like the code below. My problem
is that I can’t get the flash[:notice]'s to show up on the page.

Any thoughts on what could possibly explain the fact I can’t see the
flash in the browser?

what do your views look like?
the controller certainly looks like it’s setting the flash (and your
tests verify that)
so including somewhere in your “show.rhtml” the line “<%= flash[:status]
%>” should definitely be showing up.

Like you say, my view template has ‘<%= flash[:notice] %>’ in it. I’m
using hobo’s dryml though instead of rhtml, so that may be contributing
to the problem. I’ll check over on their list.

Thanks…

Hopefully this will help someone else. The problem was that the first
line of the ‘show’ action that the ‘do_the_action’ action was
redirecting to did this:

flash[:notice] = nil

It threw me off since the flash was being picked up in the test.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs