[Jifty-commit] r2085 - jifty/trunk/lib/Jifty/Manual
jifty-commit at lists.jifty.org
jifty-commit at lists.jifty.org
Mon Oct 30 04:49:49 EST 2006
Author: gugod
Date: Mon Oct 30 04:49:49 2006
New Revision: 2085
Modified:
jifty/trunk/lib/Jifty/Manual/Cookbook.pod
Log:
Fix typo, and add some sentences descriping an issue
when defer{} failed to dwim.
Modified: jifty/trunk/lib/Jifty/Manual/Cookbook.pod
==============================================================================
--- jifty/trunk/lib/Jifty/Manual/Cookbook.pod (original)
+++ jifty/trunk/lib/Jifty/Manual/Cookbook.pod Mon Oct 30 04:49:49 2006
@@ -78,11 +78,11 @@
zone appropriately. All dates are stored in UTC in the database, to
ensure consistency.
-=head2 Emulate 'created_on' field like Rails ?
+=head2 How do I emulate 'created_on' field like Rails ?
In Rails, if you have a field named 'created_on', it's automatically
set to the creation time of the record. How can I emulate this
-behaviour in Jifty ?
+vbehaviour in Jifty ?
The trick here is to use L<Scalar::Defer>. And declare your column
like this:
@@ -96,8 +96,11 @@
This approach is not really accurate, if you render this field in a
form, then the defer value is evaluated by the time of rendering,
which might be way eariler then the creation of record. However, it is
-the easiest one. For more accurate approch, override model's
-C<before_create()> method:
+the easiest one.
+
+If you're using the newly recommeded C<JIfty::DBI::Record schema {}>
+to declare schema, you might find this trick not working at the moment.
+Please override model's C<before_create> method instead:
sub before_create {
my ($self, $attr) = @_;
@@ -151,8 +154,8 @@
before '/logout' => {
Jifty->web->request->add_action( class => 'Logout' );
- Jifty->web->request->add_action(class => 'Redirect',
- arguments => { url => '/' });
+ Jifty->web->request->add_action( class => 'Redirect',
+ arguments => { url => '/' });
};
=head2 Pass HTML form input directly to components
@@ -193,10 +196,10 @@
Asking user to input something in a form is really common in a web
app. For some certain form fields you want them to have a certain
-normalized/canoncicalized form in database, and you could do a ajax
+normalized/canoncicalized form in database, and you could do an ajax
canonicalization in Jifty very easily. Lets say your User model need a
-canonicalized C<username> field to make sure those names are n
-lowercase. All you have to do is define a metnod named
+canonicalized C<username> field to make sure those names are in
+lowercase. All you have to do is to define a method named
C<canonicalize_username> your Model class, like this:
package MyApp::Model::User;
@@ -208,11 +211,13 @@
return lc($value);
}
-If the form is generated by a C<Jifty::Action::Record> -based action,
-then this is all you need to do. And that is probably 90% of the case.
-C<Jifty::Action::Record> would check if there is a method named like
-C<canonicalize_fieldname> when it is rendering form fields. If found,
-related javascript code is generated.
+If the form is generated by a C<Jifty::Action::Record> -based action
+(all those autogenerated CRUD actions), then this is all you need to
+do. And that is probably 90% of the case. C<Jifty::Action::Record>
+would check if there is a method named like C<canonicalize_fieldname>
+when it is rendering form fields. If found, related javascript code is
+generated. You do not have to modify any code in your view. Jifty does
+it for you.
The ajax canonicalization happenes when the input focus leaves that
field. You would see the effect a bit latter that the value in the
More information about the Jifty-commit
mailing list