You're not currently signed in.

Here are (uncategorized) questions (and hopefully answers) from early adopters.

How do I change the default rendered menu.


Besides using CSS, another options would be overriding '/menu' template. Here's an example to render your menu as an YUI menubar in your View.pm:

private template 'menu' => sub {
    outs_raw(Jifty->web->navigation->render_as_yui_menubar);
};

Here's a list of method you can also try to render different types of menu:

  • render_as_menu
  • render_as_context_menu
  • render_as_hierarchical_menu_item
  • render_as_classical_menu
  • render_as_yui_menubar

Most of these render menu as an UL element. If you need to do more then that, you'll need to traverse the menu tree on your own. Jifty->web->navigation points to a Jifty::Web::Menu object, please also read the menu of Jifty::Web::Menu for more detail. See also the mason template share/web/templates/_elements/menu.

How do I develop with Jifty and not hurt my previous cpan install of Jifty?


As a regular user (not root):

svn co http://svn.jifty.org/svn/jifty.org/Jifty-DBI/
cd Jifty-DBI/trunk
perl Makefile.PL

When it asks you to install missing components reply no for now. As root use cpan to install the missing components. Once they are all installed, then change back to a normal user and do perl Makefile.PL. It should complete without asking for any dependencies.

make
make test

Now we need to make the new Jifty-DBI lib available for when we compile jifty. To do this:

export PERL5LIB=<yourdir>/Jifty-DBI/trunk/lib
svn co http://svn.jifty.org/svn/jifty.org/jifty
cd jifty/trunk
perl Makefile.PL

When it asks you to install missing components reply no for now. As root use cpan to install the missing components. Once they are all installed, then change back to a normal user and do perl Makefile.PL. It should complete without asking for any dependencies.

make
make test

Now we need to make the new jifty executable and lib available for when we run jifty. To do this:

export PERL5LIB=<yourdir>/jifty/trunk/lib:$PERL5LIB
export PATH=<yourdir>/jifty/trunk/bin:$PATH

At the time of writing this, only 2 tests failed in jifty and 0 failed in Jifty-DBI.

On Windows, can I use the development version of Jifty ?


Why not? Here is the simple rule; to enjoy the Jifty dev, you MUST install all the prerequisite modules prior to Jifty itself. For the Jifty plugins, the rule is same. Isn't it simple?

If you don't have nmake(Windows version of make), it is going to be installed automatically by Module::Install. If you need SVN, TortoiseSVN(http://tortoisesvn.net) could be a good choice.

Because most Windows users don't have a C compiler or simply don't have interests in compiling Perl modules, installing modules that Jifty needs strongly depends on the site(s) where you can get precompiled modules.

NOTE: Jifty dev might have even serious bugs. Get prepared not to be paniced.

Here is one of tricky ways. (ActiveState's Perl)

Step 1, if you didn't install Jifty, install that from the TCOOL(http://ppm.tcool.org). This helps you install a bunch of prerequisite modules easily for Jifty.

Step 2, create a working directory(SVN checkout) for Jifty dev.

Step 3, In the working directory, try to install Jifty. Look at the error message and check what modules you need.

Step 4, Switch your PPM's repository to the site that has the modules you need, then install them.

Step 5, repeat the step 3 and 4.

Step 6, start Jifty server. You might meet with an error message saying dependency modules are not complete. If so, simply install that module(s).

The dependency modules would change from time to time. So, following the Jifty dev, you had better remember the "simple rule".

How do I delete all records from a table using a Model?


# empty table

my $system_user = CalLabCert::CurrentUser->superuser;
my $collection = CalLabCert::Model::DatFileCollection->new(current_user => $system_user);
$collection->unlimit();
while (my $item = $collection->next) { $item->delete };

How do I Migrate My Production Database ?


I have a production database that I have to keep. But my new fancy Jifty function requires a schema update. How should I migrate my production database ?

Edit etc/config.yaml and change Database->Version to a proper value (say, 0.0.2). Then run

jifty schema --setup

How do I Emulate the '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 ?

The trick here is to use Scalar::Defer. And declare your column like this:

column created_on =>
    type is 'timestamp',
    label is 'Created On',
    default is defer { DateTime->now },
    filters are 'Jifty::Filter::DateTime';

How do I Use SQLite instead of PostgreSQL?


Question

I edited Jifty's etc/config.yml to switch the Driver from Pg to SQLite. After trying to install the schema with perl bin/jifty schema --install, I receive the errors:

WARN - DBD::SQLite::db prepare failed: no such table: _db_version(1) at dbdimp.c line 268 at bin/../../Jifty/deps/Jifty/DBI/Handle.pm line 419.

WARN - Jifty::Handle=HASH(0x10d66050) couldn't prepare the query 'SELECT major, minor, rev FROM _db_version'no such table: _db_version(1) at dbdimp.c line 268

INFO - Generating SQL for application Wifty...
WARN - Couldn't require Wifty::Model::Revision : Base class package "Wifty::Record" is empty.
(Perhaps you need to 'use' the module which defines that package first.)
at lib/Wifty/Model/Revision.pm line 15
BEGIN failed--compilation aborted at lib/Wifty/Model/Revision.pm line 15.
Compilation failed in require at (eval 98) line 3.

at bin/../../Jifty/lib/Jifty/Script/Schema.pm line 111

I don't have a Wifty::Record module in my tarball.

Answer

These days, Jifty defaults to SQLite instead of PostgreSQL.

Wifty, however, defaults to the way we run it for Jifty.org. (Perhaps this should change.) Edit etc/config.yml and change the Database Driver from Pg to SQLite.

A big part of what Jifty provides to you is generic hooks for your baseclasses, so the the following virtual classes all inherit from their Jifty equivalents

YourApp::Record ISA Jifty::Record (which ISA Jifty::DBI::Record)

YourApp::Collection ISA Jifty::Collection (which ISA Jifty::DBI::Collection)

How Do I Use Template::Toolkit instead of Mason?


Wow, there are a lot of occurrences of the word Mason in the Jifty source code.

You do an awful lot of hacking. Part of the Jifty philosophy is that we provide (at least) one well integrated way to do everything you need to do. We're big fans of HTML::Mason - it's the templating toolkit that best fits with our model of things - so it's the toolkit that's well integrated into Jifty. We'd love to hear suggestions about how to get TT or other templating engines to support the bits we need.

How Do I Make my own testing framework like Rails "fixtures"?


Rails has a concept of "fixtures" that get auto-inserted into the database during testing. Can I do that in Jifty?

Sure. You need to make MyApp::Test and use that instead of Jifty::Test in your test files. Here's a sample MyApp::Test:

package MyApp::Test;
use base qw/Jifty::Test/;

sub setup {
  my $class = shift;
  $class->SUPER::setup;

  my $ADMIN = MyApp::CurrentUser->superuser;

  my $widget = MyApp::Model::Thingy->new(current_user => $ADMIN);
  $widget->create(
    foo => "bar",
    baz => "troz",
  );
  # And so on..
}

# You can also override some configuration settings:
sub test_config {
  # Customize the config file for testing
  my $class = shift;

  my ($config) = @_;
  my $hash = $class->SUPER::test_Config($config);
  $hash->{framework}{LogConfig} = "some/log4perl.conf";
  return $hash;  
}

How do I Force Users to Log In?


Certain portions of my app should only be accessible to users who have logged in. How do I enforce that?

To protect access to /admin in your "TestApp" application create a lib/TestApp/Dispatcher.pm

   use strict;
   use warnings;

   package TestApp::Dispatcher;
   use Jifty::Dispatcher -base;

   before '/admin*' => run {
      # Authentication
      Jifty->web->tangent(url => '/login')
            if (! Jifty->web->current_user->id);
   };

   1;

You could already use an autohandler or init section in a mason template, but this solutions does not respect MVC design paradigm.

In the top-level autohandler:

if (not Jifty->web->current_user->id and $m->request_comp->path !~
    m{^/(?:public|bits|like|login|css|js|images|__jifty)} ) {
    # Not logged in, trying to access a protected page;
    # Tangent to the login path.

    Jifty->web->tangent(url => '/login/');
} else {
    # Public page.  Carry on as usual.
    $m->call_next;
}

In the login element:

<%init>
# Assumes you have a YourApp::Action::Login
my $action = Jifty->web->new_action(class => 'Login', moniker => 'loginbox' );

# We should have a continuation, if we came here from the autohandler.  Otherwise,
# we make a continuation with some sane default request (like for the main page, below)
my $next = Jifty->web->request->continuation
  || Jifty::Continuation->new(request => Jifty::Request->new(path => "/some-main-protected-page"));

# Now, in the form, we set it so that that continuation is called if all of the actions go off:
</%init>
<% Jifty->web->form->start(call => $next) %>
<% $action->form_field('address') %>
<% $action->form_field('password') %>
<% Jifty->web->form->submit(label => 'Login') %>
<% Jifty->web->form->end %>

How Do I Create a radio button?


In the Jifty::Manual::Tutorial, there are examples for text boxes and textareas. How do I make a radio button?

In the same file (e.g. MyBlog/lib/MyApp/Model/Post.pm for a 'Post' [http://www.resumesplanet.com| resume] in your 'MyBlog' app) as your other columns, add one like so:

column radioband =>
    label   is 'Radio Band',
    render_as 'Radio',
    valid_values ['CB','FM','AM'],
    default 'FM';

Then update your database as usual (e.g. increment your version and jifty schema --setup).

How Do I Make a create or update form ?


my $record = TestApp::Model::Subscriber->new();
   $record->load($user);
my $action_class =  ($record->id)?'UpdateSubscriber':'CreateSubscriber';
my $action = Jifty->web->new_action(class=>$action_class, record => $record);

and

<% $action->hidden('user',$user) %>
<% $action->form_field('hotel') %>
<% Jifty->web->form->submit(
      label    => ($record->id)?'Update':'Create') %>