我有三个型号
一个user
谁提交product
S和其他用户可以order
该产品.
现在我想实现另一个模型payment
,我作为管理员付钱给用户.
问题
我很困惑我应该在什么样的关联之间创建user
,order
和payment
?
这就是我现在所拥有的:in app/models/user.rb
class User < ActiveRecord::Base
has_many :products_selling, class_name: 'Product'
has_many :orders_received, class_name: 'Order', through: :products_selling, source: :orders
has_many :orders_made, class_name: 'Order'
has_many :products_ordering, class_name: 'Product', through: :orders_made, source: :product
has_one :payment, class_name: 'Payment', through: :orders_received
Run Code Online (Sandbox Code Playgroud)
并在 app/models/order.rb
class Order < ActiveRecord::Base
belongs_to :product
belongs_to :buyer, class_name: 'User', foreign_key: :user_id
has_one :seller, class_name: 'User', through: :product
has_one :payment, …
Run Code Online (Sandbox Code Playgroud) 所以我正在尝试使用Perl学习链接列表.我正在阅读Jon Orwant的Perl掌握算法.在书中,他解释了如何创建链表.我理解其中的大部分内容,但我只是无法理解NEXT
代码片段的倒数第二行中的命令/ index/key .
$list=undef;
$tail=\$list;
foreach (1..5){
my $node = [undef, $_ * $_];
$$tail = $node;
$tail = \${$node->[NEXT]}; # The NEXT on this line?
}
Run Code Online (Sandbox Code Playgroud)
他想在那里做什么?
是$node
标量,它存储未命名数组的地址?即使我们解除引用$node
,我们也不应该通过索引号引用单个元素,例如(0,1).如果我们NEXT
用作键,是$node
对哈希的引用?我很迷茫.
用英语简单的东西将受到高度赞赏.
这就是我所拥有的
my %count_words;
while (<DATA>){
my $line= $_;
chomp $line;
my @words = split (/ /, "$line");
foreach my $word(@words){
$count_words{"$word"}++;
}
}
foreach my $key (%count_words){
print "\"$key\" occurs \"$count_words{$key}\" times\n";
}
__DATA__
we name is something
this is what it does
we food food food food
Run Code Online (Sandbox Code Playgroud)
这是我得到的输出
"it" occurs "1" times
"1" occurs "" times
"what" occurs "1" times
"1" occurs "" times
"name" occurs "1" times
"1" occurs "" times
"food" occurs "1" times
"1" occurs "" …
Run Code Online (Sandbox Code Playgroud) 所以我需要在单个HTML文件上执行多个perl正则表达式,并将每个值存储在一个数组中.
html文件看起来像
<a href="/jobs_qa">Job QA</a>
Title:
Commercial Bank
<p></p>
City:
TX
State:
TX
Country:
<p></p>
Full Description:
<p></p>
<p> Citi North America Consumer Banking group serves customers through Retail Banking, Credit Cards, Personal Banking and Wealth Management, Small Business Banking and Commercial Banking. </p>
<p>Commercial Bank Head - Houston-11030087</p>
<p>Description </p>
<p>POSITION SUMMARY</p>
<p>Lead the sales, relationship, and credit management for commercial banking customers in a given marketplace. Build and motivate talented relationship teams to effectively penetrate the market and …
Run Code Online (Sandbox Code Playgroud)