[jifty-devel] Struggling with Jifty

Ruslan Zakirov ruz at bestpractical.com
Sat May 15 12:36:27 EDT 2010


On Sat, May 15, 2010 at 12:07 PM, Jes <jjjesss at gmail.com> wrote:
> El Sat, 15 May 2010 05:08:49 +0100
> Sadia Lone <l at mavsol.com> escribió:
>
>> An absolute newbie here:

[snip]

> Hi Sadia:
>
> Well, I'm not an expert in Jifty, but from my experience, you cand edit
> or delete in a similar way you create the post, using autoclasses (is it
> the right name?). For example, to edit a record (to modify it):
>
>   template '/edit_post' => page { title => 'Edit Post Entry' } content
>   {
>        my $postid = get 'postid';
>
>        my $post = MyWeblog::Model::Post->new;
>        $post->load($postid);

[snip]

>        };
>
> This page would be called as 'http://xxxxx/edit_post/1' for example, to
> edit postid=1. So in the dispatcher you need something like:
>
> before qr'/edit_post/(\d+)' => run {
>        set postid => $1 ; #this is to send the postid to the view
> };
>
> on '/edit_post/*' => run {
>    show '/edit_post' ;
> };

In my experience it's better to move slightly more things into dispatcher:

on '/edit_post/*' => run {
    # * - also captures so you can do the following and don't need before rule:
    my $id = $1;

    # load right in dispatcher
    my $post = Jifty->app_class('Model::Post');
    $post->load( $id );

    # "404: not found" if not found
    abort(404) unless $post->id;

    # store object instead of id
    set post => $post;

    show '/edit_post' ;
};

[snip]

I hope once you implement this and learn new tricks, you send us
patches for documentation to make things clearer for other newbies :)

-- 
Best regards, Ruslan.


More information about the jifty-devel mailing list