Advertisement
Guest User

Flash not working

a guest
Apr 18th, 2012
16
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 0.98 KB | None | 0 0
  1. use Mojolicious::Lite;
  2. use Data::Dumper;
  3.  
  4. get '/' => 'index';
  5. get '/another-action' => 'another-template';
  6.  
  7. ###############################
  8. # Adds a new node to the tree #
  9. ###############################
  10. post '/new' => sub {
  11.  
  12.     my $self = shift;
  13.     my $num  = $self->param('num');
  14.  
  15.     $self->flash( error => "Parent node not found" ) if $num < 10;
  16.  
  17. # I got some problems here with Flash, so I did in an alternative way
  18. #$self->stash->{'mojo.session'}->{flash}->{error} = "error comes here";
  19. #app->log->info( Dumper ( $self->stash->{'mojo.session'} ) );
  20. #app->log->info( Dumper ( $self->flash("error") ) );
  21.  
  22.     # Redirects to Tree listing page
  23.     $self->redirect_to('/another-action');
  24. };
  25.  
  26. app->start;
  27.  
  28.  
  29. __DATA__
  30. @@ another-template.html.ep
  31. %= flash 'error'
  32.  
  33. @@ index.html.ep
  34. <form action='/new' method='post'>
  35. Type a number bigger then 10:
  36. <input type='text' name='num' size='5'/>
  37. <span class='error'>Erro: <%= flash 'error' %></span>
  38. <input type='submit' value='Check'/>
  39. </form>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement