[dancer-users] updating a form

Gert van Oss gertvanoss at me.com
Mon Feb 10 13:37:29 GMT 2014


I’m trying to build a small app to comment on images. Probably I’m almost there but currently stuck with updating a ‘file.yml' by a html-form. 

I’ve made two routes (shown below) “get ‘/:id/edit’ for showing the form with the particular image to comment on. When hitting save the ‘post ‘/edit’ will be called. My problem is that the post route doesn’t have the $id initialised. Is there someone around who can tell me how to solve this or point to me what I’m doing wrong?


The structure is an AoH. 
The file.yml is like

- collection: ''
  description: good
  id: 0
  imgf: photo.jpg
  tags: ''
- collection: ''
  description: ''

————end of yaml

# get EDIT
get '/:id/edit' => sub {
    my $filename =
        Dancer::FileUtils::path( setting('appdir'), 'myImages.yml' ) );
    my $data = from_yaml $filename;
    my @data = @{$data};

    #print Dumper \@data;
    my $id = param('id');
    template 'edit', { data => $data[$id], id => $id, };

# post EDIT

post '/edit' => sub {
    my $data = get_AoH_imagelist();
    my @data = @{$data};
    my $id   = param('id');
    $data[$id] { description}=  params->{description} ;
    #$data[2] { description}=  params->{description} ; 
    # this works but then all descriptions end up in the third group of hashes.
    my $filename = "myImages.yml";
    write_file $filename, to_yaml($data);
    redirect '/';

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.preshweb.co.uk/pipermail/dancer-users/attachments/20140210/54871e7f/attachment.html>

More information about the dancer-users mailing list