如何从动作渲染视图中发送参数
#!/usr/bin/perl
use strict;
use threads;
use threads::shared;
use Thread::Queue;
my $queue = Thread::Queue->new();
my @threads;
my $thr;
#----------------------------------------create
#send work first,and then creat threads, the first thread work earlier.
$queue->enqueue(1..10000);
foreach (1..5)
{
push @threads,threads->create("worker");
}
$queue->end();
sub worker
{
while (my @DataElement = $queue->dequeue(100))
{
my $tid = threads->tid();
#open (my $out,">>$tid.txt") or die $!;
print "Threads ID:$tid\t@DataElement\n";
#print $out "Threads ID:$tid\t@DataElement\n";
#close $out;
}
}
#----------------------------------------cut
my $thr_num=1;
my $i;
while ($thr_num)
{
$i++;
foreach (@threads) #store threads, TRUE even if joined.
{
$thr_num = threads->list();
print "threads total: $thr_num\n";
if ($_->is_running())
{
sleep 1; #wait
next;
}
if ($_->is_joinable())
{
$_->join();
}
sleep 1;# wait
}
print $i,"\n";
}
但respond_to do |format|
if @donation.save
else
format.html { render :new,:locals => { :need_id => @need_id }}
end
end
可访问need_id
我如何通过这个参数?
答案 0 :(得分:1)
如果您已在控制器中定义@need_id
。它将在相应的视图文件中提供:
查看文件(.html.erb):
<%= @need_id %>
答案 1 :(得分:0)
如果控制器中有@need_id,那么
format.html { render :new,:locals => { :need_id => @need_id }}
你可以做&lt;%= need_id%&gt;在视图文件中。