[jifty-devel] Struggling with Jifty

Jes jjjesss at gmail.com
Sat May 15 04:07:27 EDT 2010

El Sat, 15 May 2010 05:08:49 +0100
Sadia Lone <l at mavsol.com> escribió:

> An absolute newbie here:
> I have been struggling with Jifty for the last couple of weeks. My
> progress:
> 1. I was able to successfuly install jifty after many tries.
> 2. I have been able to create and run the tutorial blog application at
> http://search.cpan.org/~alexmv/Jifty-0.91117/lib/Jifty/Manual/Tutorial.pod
> I would really appreciate if someone can:
> 1. Point out how can I write few more lines to edit/delete the post.
> To explain a bit, the following snippet is for adding a new post:
>   package MyWeblog::View;
>   use strict;
>   use warnings;
>   use Jifty::View::Declare -base;
>   template post => page { title => 'Post Entry' } content {
>       my $action = new_action(class => 'CreatePost');
>       form {
>           render_action $action;
>           form_submit(label => 'Post');
>       }
>   };
>   1;
> I want a similar code snippet for editing and deleting an existing
> post.
> I know I can do these operations from admin interface but I want to do
> these from my own code so that I can add/remove columns as required
> and add validation etc.
> Since I am a newbie to programming as well I could not make sense out
> of all docs I read (Jifty::Action etc.)
> 2. A ready made jifty application somewhere on Internet with just
> basic operations for a database table (CREATE, INSERT, UPDATE, DELETE)
> All documentation at jifty.org or cpan looks like has been written for
> experts. If there is anything I missed, point me to that.
> Thx
> S.Lone
> _______________________________________________
> jifty-devel mailing list
> jifty-devel at lists.jifty.org
> http://lists.jifty.org/cgi-bin/mailman/listinfo/jifty-devel

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; 
	my $action = new_action(class => 'UpdatePost', record=>$post); 
                                         #^^^^^^Here is the magic 
	form {
           render_param( $action , 'param') ; 	#where param is
           					#the column in your
           					#model you want to
						#Probably you need more
						#fields to update a
		form_submit(label =>
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' ;

Well, take care with this code because it was typed on fly so probably
is buggy. You can do more or less the same to delete records. In this
case, probably you want to add some code for show a confirmation box
before delete the record. For example:

                  label   => 'Delete',
		  onclick => {
                              confirm => 'Are you sure? ',
	                     url     => '/delete_post/' . $post->id , 
Or something similar. And the autoclass in this case (when you define
the action) would be "DeletePost". Or you can create a specific
deletion action from command line, and in the file generated (for
example DelPost.pm) delete the record with something like:

	my $post = MyWeblog::Model::Post->new;
	$post->load( $postid);

Obiously you need to call the action from the dispatcher, send it the
post_id, and so... More info in the docs and google :).

Probably other people in this list help you with more precise examples.

Best regards,


More information about the jifty-devel mailing list