I'm having an issue with Mojolicious and the stash and I think I'm probably just not understanding the way it works? I have a page with 2 combo boxes and when the first entry changes I wish to update the options in the second.
So I add an event handler like below, which then calls my controller sub routine 'devicecommandset' and then puts the result of a DBIx query into an array of hashes which I add to my stash.
I am then just render some benign text. My subroutine gets called and there is the expected contents in '@commandsets'. However I cannot see it in the stash on the browsers console ( I'm running in debug mode ).
Do I need to actually modify the DOM for the stash to be populated? Basically I'm just trying to get data back from my request to fill the combobox options.
In my template
$(document).ready(function() {
$('select:not([name*="command"])').live('change', function (e) {
$.get('devicecommandset', { device: $(this).attr("value") },
function (data) {
alert("Made it this far");
});
});
});
In my Controller
sub devicecommandset {
my $self = shift;
my $device = $self->param('device') || '';
my @commandsets = $self->db->resultset('CommandSet')->search_commandsets_by_devicename($device);
$self->stash(commandsets => \@commandsets );
print Dumper(@commandsets);
$self->render(text => 'success' );
}
You're printing a dumper to the log basically, not the browser. Your stash is not used in the render because you're not referencing it. Use inline render type and the "dumper" helper. Try:
$self->stash(commandsets => \@commandsets );
$self->render( inline => '<%= dumper $commandsets %>' );