Skip Menu |

This queue is for tickets about the Dancer-Plugin-FlashMessage CPAN distribution.

Report information
The Basics
Id: 65009
Status: resolved
Priority: 0/
Queue: Dancer-Plugin-FlashMessage

People
Owner: DAMS [...] cpan.org
Requestors: lozier [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



Subject: Message never shows up in template
I am trying to follow the examples and am unable to get it to work as advertised. I can set a message with flash error => 'some error'; Then I can verify that it exists in my session on the next page view: [11520] warn @0.001062> [hit #1] $VAR1 = bless( { 'id' => '58434346941446644293786320501729180', '_flash' => { 'error' => 'some warning message' } }, 'Dancer::Session::YAML' ); in /home/brian/sites/goyaads/lib/goyaads.pm l. 14 My handler for that looks like this: get '/' => sub { warning Dumper(session()); template('index'); }; The main.tt has this in it: <% IF flash.error %> <div class=error> <% flash.error %> </div> <% END %> But the error never shows up. The only way I can get it to show up is to manually pull it out in the handler like this: get '/' => sub { warning Dumper(session()); template('index', {error => flash 'error'}); }; And then change the template to look like this: <% IF error %> <div class=error> <% error %> </div> <% END %> I would like to understand how "flash.error" is supposed to be set in the template because it appears it never gets there. Is the documentation wrong? Did I miss something? Thanks!
On Fri Jan 21 17:18:50 2011, LOZIER wrote: Show quoted text
> I am trying to follow the examples and am unable to get it to work as > advertised. I can set a message with flash error => 'some error'; Then > I can verify that it exists in my session on the next page view: > > [11520] warn @0.001062> [hit #1] $VAR1 = bless( { > 'id' => '58434346941446644293786320501729180', > '_flash' => { > 'error' => 'some warning message' > } > }, 'Dancer::Session::YAML' ); in > /home/brian/sites/goyaads/lib/goyaads.pm l. 14 > > My handler for that looks like this: > > get '/' => sub { > warning Dumper(session()); > > template('index'); > }; > > The main.tt has this in it: > > <% IF flash.error %> > <div class=error> <% flash.error %> </div> > <% END %> > > But the error never shows up. The only way I can get it to show up is > to manually pull it out in the handler like this: > > get '/' => sub { > warning Dumper(session()); > > template('index', {error => flash 'error'}); > }; > > And then change the template to look like this: > > <% IF error %> > <div class=error> <% error %> </div> > <% END %> > > I would like to understand how "flash.error" is supposed to be set in > the template because it appears it never gets there. Is the > documentation wrong? Did I miss something? Thanks!
I was able to get this to work suddenly using your examples but the flash message is persistent. The only way to get rid of it is to call flash 'error'; which is not called by default when the value is rendered in the template. I think the example is broken, in order to get the correct behavior I have to call the flash 'error' function manually as in my last message anyway.
Hi, thanks for your bug report. I have fixed the persistence issue. Now by default flash messages are not persistent : they are removed from the session at the end of the request. Note that it's at the end of the request, not just after the first template has been issued. You can potentially do more than one view or layout rendering in the same request. They would all see the flash message. At the end of the request however, the flash messages hash is removed. That is, unless you override the default, and set 'persistence' to a true value in the configuration. I've juste pushed version 0.305 which implements all that. Let me know if it works for you. About your troubles at the beginning of your bug report : what was the issue ? Even if you figured it out, I'd be interested to know if I could make it easier for user to make it work, maybe by updating the doc. Thanks, dams
Subject: Re: [rt.cpan.org #65009] Message never shows up in template
Date: Wed, 26 Jan 2011 07:32:22 -0800
To: bug-Dancer-Plugin-FlashMessage [...] rt.cpan.org
From: "Brian E. Lozier" <brian [...] massassi.com>
Thanks for your prompt attention. Unfortunately I am unable to reproduce the original error. I may have been doing something wrong as I'm new to Dancer. To address the changes you made to the Plugin, I think we're moving in the right direction. However, here is how I think of flash messages and how they should work. If I'm not thinking of this correctly, please tell me. A user submits a form. We want to process the form and send a message back to the user that the form was processed successfully. We typically don't want to have the success message on the same page as the form processing because it's too easy to accidentally press reload and resubmit the data. So the normal pattern we use is: show a form user posts to /process /process processes the form, sets a flash message, and then forwards the user to /something-else since the flash message is saved in a session, it's available on /something-else even though it's a separate request /something-else shows the flash message, and then importantly, deletes the flash message from the session so it doesn't get shown again I like to have "global" handling of flash messages. (I've typically done this myself using CGI::Application). This means that the flash messages should only ever be shown once but that they should only be deleted when we're sure they were shown. So for my Dancer app I'm working on I made a before_template hook to delete the flash message. This isn't ideal because it's not guaranteed that every time I show a template it's the "layout" which has the flash message handling. I'm not familiar with writing Dancer plugins but it seems like the most useful case would be to, instead of just providing the data to the template, maybe provide a function to the template. When called, the function would fetch the message from the session and then delete it from the session and then return it. That way, I wouldn't have to have any extra logic to try to figure out whether it's shown. The perl logic looks something like this, I'm not sure how to make that work with template::toolkit or whatever: if(my $warning = flash('warning')) { show_warning($warning); } In order to please template::toolkit or others, it may be that we need two functions, something like flash_exists('warning') and then the flash('warning') itself. With those, the logic for showing flash messages and deleting them from the session will reside solely in the plugin and the template. In the application logic, all we have to do is set the flash message and then the rest is taken care of automatically. On Sun, Jan 23, 2011 at 10:28 AM, Damien Krotkine via RT <bug-Dancer-Plugin-FlashMessage@rt.cpan.org> wrote: Show quoted text
> <URL: https://rt.cpan.org/Ticket/Display.html?id=65009 > > > Hi, > > thanks for your bug report. > > I have fixed the persistence issue. Now by default flash messages are not persistent : they are > removed from the session at the end of the request. > > Note that it's at the end of the request, not just after the first template has been issued. You > can potentially do more than one view or layout rendering in the same request. They would > all see the flash message. At the end of the request however, the flash messages hash is > removed. > > That is, unless you override the default, and set 'persistence' to a true value in the > configuration. > > I've juste pushed version 0.305 which implements all that. Let me know if it works for you. > > About your troubles at the beginning of your bug report : what was the issue ? Even if you > figured it out, I'd be interested to know if I could make it easier for user to make it work, > maybe by updating the doc. > > Thanks, > dams >
These issues should be resolved in the latest version of the module. Please reopen this ticket if it's not the case.