Skip to content

Instantly share code, notes, and snippets.

@note103
Created March 22, 2014 08:48
Show Gist options
  • Save note103/9703386 to your computer and use it in GitHub Desktop.
Save note103/9703386 to your computer and use it in GitHub Desktop.
#!/usr/bin/env perl
use Mojolicious::Lite;
my @entries = {};
get '/' => sub {
my $self = shift;
$self->stash(entries => \@entries);
$self->render('index');
};
post '/post' => sub {
my $self = shift;
my $n_in = $self->param('name_in');
my $e_in = $self->param('email_in');
my $t_in = $self->param('text_in');
push @entries, {
n_out => $n_in,
e_out => $e_in,
t_out => $t_in,
};
$self->redirect_to('/');
};
app->start;
__DATA__
@@ index.html.ep
% layout 'default';
% title '入力フォーム';
%= form_for '/post' => method => 'POST' => begin
<table>
<tr>
<td>
name:
</td>
<td>
%= text_field 'name_in'
</td>
</tr>
<tr>
<td>
email:
</td>
<td>
%= text_field 'email_in'
</td>
</tr>
<tr>
<td>
text:
</td>
<td>
%= text_field 'text_in'
</td>
</tr>
<tr>
<td>
</td>
<td>
%= submit_button '投稿する'
</td>
</tr>
</table>
% end
% for my $entry (@{$entries}) {
<p><%= $entry->{n_out} %></p>
<p><%= $entry->{e_out} %></p>
<p><%= $entry->{t_out} %></p>
<hr>
% }
@@ layouts/default.html.ep
<!DOCTYPE html>
<html>
<head><title><%= title %></title></head>
<body><%= content %></body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment