Facebook
From Gruff Parakeet, 6 Years ago, written in Perl.
This paste is a reply to Re: Untitled from Soft Terrapin - go back
Embed
Viewing differences between Re: Untitled and Re: Re: Untitled
####_form.# Create helper
$app->helper(category_select => sub {
  my ($self, $id) = @_;

  my $categories = $self->app->db->resultset('Category');
  
  my $options = Mojo::Collection->new(['*' => 0]);
  while (my $category = $categories->next) {
    my @attr;
    push @attr, selected => 'selected' if $category->id == $id;
    push @{$options}, [$category->name, $category->id, @attr];
  }

  return $options;
});

# _form.
html.ep

#Under code I don't know to move to Controller
% my $categories = Mojo::Collection->new(['*' => 0]);
% my $cats = $self->db->resultset('Category');
% while (my $cat = $cats->next) {
%  my @attr;
%  push @attr, selected => 'selected' if $cat->id eq $category->id;
%  push @{$categories}, [$cat->name, $cat->id, @attr];
% }

#Under code must automatically select 'saved item at created or last change'
ep

  % my $options = category_select $category->id;
  
%= select_field parent_id => $categories $options => (class=>'input')




####edit.html.ep

% layout 'admin', title => 'Jizzy.eu: Edycja Kategorii';
% my $category = $self->db->resultset('Category')->find($self->stash('id'));

Category Edit [<%= $category->id %>]



%= form_for 'update_category' => (method => 'POST') => begin
  %= include '/categories/_form', category => $category

        
          %= link_to "Back" => "/categories", class => 'button', style=>"flex:1"
          %= submit_button 'Update', class => 'button is-primary', style=>"flex:1"
        
% end