小编Ame*_*mey的帖子

属于两个模型或多态关联的模型?

我有三个型号

  1. 用户
  2. 产品
  3. 订购

一个user谁提交productS和其他用户可以order该产品.

现在我想实现另一个模型payment,我作为管理员付钱给用户.

问题 我很困惑我应该在什么样的关联之间创建user,orderpayment

这就是我现在所拥有的: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)

ruby-on-rails associations models ruby-on-rails-4

2
推荐指数
1
解决办法
3197
查看次数

Perl中链接列表创建中NEXT的含义

所以我正在尝试使用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对哈希的引用?我很迷茫.

用英语简单的东西将受到高度赞赏.

perl linked-list

1
推荐指数
1
解决办法
1253
查看次数

由autovivification创建的哈希有额外的密钥

这就是我所拥有的

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)

perl hash autovivification

1
推荐指数
2
解决办法
114
查看次数

在单个HTML文件中Perl多个正则表达式

所以我需要在单个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)

html regex perl

0
推荐指数
1
解决办法
193
查看次数