#__PACKAGE__->config(namespace => 'room');
use Chatty::Form::RoomCreate;
+use Chatty::Form::MessageCreate;
has 'roomcreate_form' => (
isa => 'Chatty::Form::RoomCreate',
default => sub { Chatty::Form::RoomCreate->new }
);
+has 'messagecreate_form' => (
+ isa => 'Chatty::Form::MessageCreate',
+ is => 'rw',
+ lazy => 1,
+ default => sub { Chatty::Form::MessageCreate->new }
+);
+
=head1 NAME
Chatty::Controller::Chat - Catalyst Controller
$c->detach('/missing') if !$c->stash->{room};
$c->stash(messages => [$c->model('DB::Message')->search(room => $room)]);
+
+ $c->stash(form => $self->messagecreate_form);
+
+ my $new_message = $c->model('DB::Message')->new_result({
+ author => $c->user->obj->id,
+ room => $c->stash->{room}->id
+ });
+ $self->messagecreate_form->process(
+ item => $new_message,
+ params => $c->req->params
+ );
+
+ if (!$self->messagecreate_form->is_valid) {
+ if ($c->req->method eq 'POST') {
+ $c->stash->{error} = "The form has a validation error. Try again...";
+ }
+ return;
+ }
+
+ $c->res->redirect($c->uri_for_action('/chat/view', $c->stash->{room}->id));
}
=head1 AUTHOR