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