问题列表 - 第41117页

如何使用命名空间中的模型执行has_many

Rails 3为我们提供了这些很好的生成器,可以将模型和控制器放入命名空间,哇!但现在我无法将它们与其他模型联系起来.

我试图通过与命名空间模型的关联来实现has_many.我已经在互联网上搜索了几天,我还没有提出任何例子.

/app/models/templates/practice.rb

class Templates::Practice < ActiveRecord::Base
  has_many :practice_sequences, :order => "position", :dependent => :destroy, :class => 'Templates::PracticeSequence'
  has_many :seasons, :through => :practice_sequences, :order => "position", :class => 'Templates::Season'
end
Run Code Online (Sandbox Code Playgroud)

/app/models/templates/season.rb

class Templates::Season < ActiveRecord::Base
  has_many :practice_sequences, :order => "position", :class => 'Templates::PracticeSequence'
  has_many :practices, :through => :practice_sequences, :order => "position", :class => 'Templates::Practice'
end
Run Code Online (Sandbox Code Playgroud)

/app/models/templates/practice_season.rb

class Templates::PracticeSequence < ActiveRecord::Base
  belongs_to :practice, :class => 'Templates::Practice'  
  belongs_to :season, :class => 'Templates::Season'
end
Run Code Online (Sandbox Code Playgroud)

这是错误

/Users/jspooner/.rvm/gems/ree-1.8.7-2010.02/gems/activesupport-3.0.1/lib/active_support/core_ext/hash/keys.rb:43:in `assert_valid_keys': Unknown key(s): class (ArgumentError)
 from …
Run Code Online (Sandbox Code Playgroud)

ruby activerecord ruby-on-rails-3

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

对于ZSH,我可以控制你的行为和Bash一样吗?

在Bash中,control-u将从光标清除到行的开头,并将该文本放入粘贴缓冲区,可以使用control-y粘贴.

在Zsh中,它将清除文本,但不会将其放入缓冲区.

悲伤.

bash zsh

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

为什么"Namespace'http://www.w3.org/XML/1998/namespace'无法在此模式中引用."?

在Visual Studio 2010中查看来自http://xmpp.org/schemas/的stanzaerror.xsd时,我收到以下行的警告......

<xs:attribute ref='xml:lang' use='optional'/>
Run Code Online (Sandbox Code Playgroud)

警告:

命名空间" http://www.w3.org/XML/1998/namespace "无法在此架构中引用.

这似乎是一个非常基本的XML警告 - 任何想法?

<?xml version='1.0' encoding='UTF-8'?>    
<xs:schema
    xmlns:xs='http://www.w3.org/2001/XMLSchema'
    targetNamespace='urn:ietf:params:xml:ns:xmpp-stanzas'
    xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'
    elementFormDefault='qualified'>

  <xs:element name='bad-request' type='empty'/>
  <xs:element name='conflict' type='empty'/>
  <xs:element name='feature-not-implemented' type='empty'/>
  <xs:element name='forbidden' type='empty'/>
  <xs:element name='gone' type='xs:string'/>
  <xs:element name='internal-server-error' type='empty'/>
  <xs:element name='item-not-found' type='empty'/>
  <xs:element name='jid-malformed' type='empty'/>
  <xs:element name='not-acceptable' type='empty'/>
  <xs:element name='not-allowed' type='empty'/>
  <xs:element name='not-authorized' type='empty'/>
  <xs:element name='payment-required' type='empty'/>
  <xs:element name='policy-violation' type='empty'/>
  <xs:element name='recipient-unavailable' type='empty'/>
  <xs:element name='redirect' type='xs:string'/>
  <xs:element name='registration-required' type='empty'/>
  <xs:element name='remote-server-not-found' type='empty'/>
  <xs:element name='remote-server-timeout' type='empty'/>
  <xs:element name='resource-constraint' type='empty'/> …
Run Code Online (Sandbox Code Playgroud)

xml xsd

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

在nhibernate中,无法更新子对象列表

我有X其中类型的对象_对象具有属性ListOfObjectYs那一个

List<objectY>
Run Code Online (Sandbox Code Playgroud)

nhibernate映射看起来像这样:

    public ObjectXMap()
    {
        HasMany(x => x.ListOfObjectYs).AsBag().Inverse(); 
    }
Run Code Online (Sandbox Code Playgroud)

当我去保存它时,我在objectX上更改了一些属性,然后:

    Session.SaveOrUpdate(x);
Run Code Online (Sandbox Code Playgroud)

现在我需要更新这个列表的属性.我得到一个新的objectYs列表,我想用一个新列表替换现有的objectY列表.我需要这样做吗?

  foreach (ObjectY y in x.ListOfObjectYs)
                {
                   Session.Delete(y);
                    deleted = true;
                }
                if (deleted)
                {
                   _session.Flush();
                }
                x.ListOfObjectYs.Clear();

                foreach (ObjectY y in newObjectYList)
                {
                    x.ListOfObjectYs.Add(y);
                   Session.SaveOrUpdate(y);
                }
                _session.Flush();
Run Code Online (Sandbox Code Playgroud)

我的问题是:

  1. 在添加新内容之前,我是否必须删除所有内容并刷新.
  2. 我是否需要在两者之间进行所有这些增量保存

是否有更好的方法来执行此更新,我需要更新对象(属性),但也更新列表中存在全新列表的属性(意味着需要删除和添加项目).

c# nhibernate asp.net-mvc fluent-nhibernate

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

如何在rails 3控制器生成器中使用`--helper`标志?

来自的文件rails generate controller说:

[--helper]                # Indicates when to generate helper
                          # Default: true
Run Code Online (Sandbox Code Playgroud)

现在,它没有指定如何指示值.因此,由于默认值为true,这意味着排除它不会指示false,因为... true是默认值.所以它必须是--helper=false或者--helper false,但我尝试了两者,并且它们都导致了error false [not found]

好消息是它没有生成助手,因为它很混乱,所以我仍然得到了我想要的结果:)

ruby-on-rails generator helper helpers ruby-on-rails-3

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

通过多个索引引用PHP数组

这可能是某种奇怪的更长的捷径,如果我在这个思路上错了,请纠正我...

我有一个数据矩阵,看起来像:

unique_id | url | other random data...
unique_id | url | other random data...
unique_id | url | other random data...
Run Code Online (Sandbox Code Playgroud)

我希望能够通过它的url引用一个项目,或者它的unique_id - 是否有一种奇特的方式来做到这一点?

我想作弊的解决方案就是制作两个阵列,但我想知道是否有更好的方法.

php arrays multidimensional-array

6
推荐指数
2
解决办法
2万
查看次数

线程可以共享同一个客户端套接字吗?

我使用TClientSocket或indy的TIdTCPClient(取决于项目)

我有几个Threads每个处理项目,有时需要通过连接的客户端套接字发送数据.(数据读取形式的套接字不用于处理线程)

基本上我的问题是......

  • 有可能吗?
  • 它"安全"吗?

或者我应该

  • 每个线程或一个客户端套接字
  • 某些编组/关键部分

delphi-7 indy-9

sockets delphi multithreading delphi-7

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

XSL仅在for-each中显示10个循环

我的XML有100个AgentSales节点我到目前为止只想显示前10个节点

<xsl:for-each select="NewDataSet/AgentSales">
    <tr>
        <xsl:if test="(position() mod 2 = 1)">
            <xsl:attribute name="bgcolor">#cccccc</xsl:attribute>
        </xsl:if>
        <td>
            <span style="font:20px arial; font-weight:bold;">
                <xsl:value-of select="AgentName"/>
            </span>
        </td>
        <td>
            <span style="font:20px arial; font-weight:bold;">
                <xsl:value-of select="State"/>
            </span>
        </td>
        <td>
            <span style="font:20px arial; font-weight:bold;">
                <xsl:value-of select="time"/>
            </span>
        </td>
    </tr>
</xsl:for-each>
Run Code Online (Sandbox Code Playgroud)

网站的新功能,但当我使用代码括号时,并非我的所有代码都显示?至少不在下面的预览中.

xslt

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

SQL Server 2008数据库归类转换

我想配置具有" Latin1_General_CP1_CI_AS " 的确切需求排序规则的数据库,但由于某种原因在SQL Server 2008中,我只能选择" SQL_Latin1_General_CP1_CI_AS "?

如何选择正确的排序规则并将其从SQL_Latin1_General_CP1_CI_AS更改为Latin1_General_CP1_CI_AS

同时保留所有数据和设置(架构和登录等)? 替代文字

谢谢.

sql-server collation

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

升级到1.45时BouncyCastle AES错误

最近从BC 1.34升级到1.45.我用以下方法解码一些以前编码的数据:

    SecretKeySpec skeySpec = new SecretKeySpec(raw, "AES");
    Cipher cipher = Cipher.getInstance("AES");
    cipher.init(Cipher.DECRYPT_MODE, skeySpec);
    byte[] decrypted = cipher.doFinal(encrypted);
Run Code Online (Sandbox Code Playgroud)

当使用BC 1.45时,我得到了这个例外:

javax.crypto.BadPaddingException: pad block corrupted
 at org.bouncycastle.jce.provider.JCEBlockCipher.engineDoFinal(JCEBlockCipher.java:715)
 at javax.crypto.Cipher.doFinal(Cipher.java:1090)
Run Code Online (Sandbox Code Playgroud)

编辑:有关此问题的更多信息.我使用以下方法从密码短语生成原始密钥:

    KeyGenerator kgen = KeyGenerator.getInstance("AES", "BC");
    SecureRandom sr = SecureRandom.getInstance("SHA1PRNG", "Crypto");
    sr.setSeed(seed);
    kgen.init(128, sr);
    SecretKey skey = kgen.generateKey();
    byte[] raw = skey.getEncoded();
Run Code Online (Sandbox Code Playgroud)

我发现,这导致BC 1.34和1.45两个不同的值.

它可能也不是BouncyCastle相关的(我在Android 2.3上测试)

java android cryptography bouncycastle

6
推荐指数
2
解决办法
4156
查看次数