小马和续集的协会有冲突吗?

发布于 2024-11-03 06:52:37 字数 1756 浏览 4 评论 0原文

我在 Sinatra 应用程序中使用 Pony 和 Sequel 时遇到了问题。 没有小马,一切都会很好,但只需要小马续集的关联打破。 这是我的博客模型:

class Post < Sequel::Model

    one_to_many :comments, :order => :date.asc(), :conditions => {:approved => 1}

  set_schema do
    primary_key :id
    varchar :title
    varchar :text
    varchar :category
    varchar :status
    datetime :date
    varchar :link
  end
end

class Comment < Sequel::Model
    plugin :validation_helpers  
  many_to_one :posts
  attr_accessor :ip, :user_agent, :referrer, :permalink

  set_schema do
    primary_key :id
    integer :post_id
    varchar :author
    varchar :comment
    DateTime :date
    varchar :email
    varchar :url
    varchar :approved
  end

然后我在一条路线中像这样调用它们

post '/:link' do
  @post = Post[:link=>params[:link]]
  params[:comment].merge!( {
        :ip         => request.ip.to_s,
        :user_agent => request.env['HTTP_USER_AGENT'].to_s,
        :referrer   => request.env['REFERER'].to_s,
        :permalink  => request.env['REFERER'].to_s
  } )
  begin
    @comment = Comment.create params[:comment]
    @post.add_comment @comment
  rescue
    @message = $!
  end
  @title = @post.title
  haml :posts
end

,我什至不必在某个地方调用 pony,只需要求它 @post.add_comment @comment 失败。它说

NoMethodError - undefined method `_add_comments' for #<Post:0x102b09890>:
 /Library/Ruby/Gems/1.8/gems/sequel-3.21.0/lib/sequel/model/associations.rb:1078:in `send'
 /Library/Ruby/Gems/1.8/gems/sequel-3.21.0/lib/sequel/model/associations.rb:1078:in `add_associated_object'
 /Library/Ruby/Gems/1.8/gems/sequel-3.21.0/lib/sequel/model/associations.rb:743:in `add_comment'

在我看来似乎与发送有冲突?我什至不知道如何开始调试它。

I've run into an issue when using Pony and Sequel in a Sinatra application.
Without Pony everything goes just fine, but just requiring Pony sequel's associations break.
Here's my models for a blog:

class Post < Sequel::Model

    one_to_many :comments, :order => :date.asc(), :conditions => {:approved => 1}

  set_schema do
    primary_key :id
    varchar :title
    varchar :text
    varchar :category
    varchar :status
    datetime :date
    varchar :link
  end
end

class Comment < Sequel::Model
    plugin :validation_helpers  
  many_to_one :posts
  attr_accessor :ip, :user_agent, :referrer, :permalink

  set_schema do
    primary_key :id
    integer :post_id
    varchar :author
    varchar :comment
    DateTime :date
    varchar :email
    varchar :url
    varchar :approved
  end

Then I call them like this in a route

post '/:link' do
  @post = Post[:link=>params[:link]]
  params[:comment].merge!( {
        :ip         => request.ip.to_s,
        :user_agent => request.env['HTTP_USER_AGENT'].to_s,
        :referrer   => request.env['REFERER'].to_s,
        :permalink  => request.env['REFERER'].to_s
  } )
  begin
    @comment = Comment.create params[:comment]
    @post.add_comment @comment
  rescue
    @message = $!
  end
  @title = @post.title
  haml :posts
end

I don't even have to call pony somewhere, just requiring it @post.add_comment @comment fails. It says

NoMethodError - undefined method `_add_comments' for #<Post:0x102b09890>:
 /Library/Ruby/Gems/1.8/gems/sequel-3.21.0/lib/sequel/model/associations.rb:1078:in `send'
 /Library/Ruby/Gems/1.8/gems/sequel-3.21.0/lib/sequel/model/associations.rb:1078:in `add_associated_object'
 /Library/Ruby/Gems/1.8/gems/sequel-3.21.0/lib/sequel/model/associations.rb:743:in `add_comment'

Seems to me like a conflict with send? I don't even know how to start to debug it.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

鱼忆七猫命九 2024-11-10 06:52:37

不管您相信与否,这是由 ActiveSupport 问题引起的。您应该下降到 ActiveSupport 3.0.3 或通过以下方式手动要求默认的 ActiveSupport 变形:

require 'active_support/inflections'

基本上,在 3.0.3 之后,ActiveSupport 可以在没有默认变形的情况下加载变形器,这会导致单数和复数方法损坏。我猜 pony 使用的邮件 gem 是已知会被此更改破坏的库之一。

Rails 开发人员显然不认为这是 ActiveSupport 中的错误,而是使用 ActiveSupport 的库中的错误。

This is caused by an ActiveSupport issue, believe it or not. You should drop down to ActiveSupport 3.0.3 or manually require the default ActiveSupport inflections via:

require 'active_support/inflections'

Basically, after 3.0.3, ActiveSupport made it possible to load the inflector without the default inflections, which results in broken singularize and pluralize methods. The mail gem, which I'm guessing pony uses, is one of libraries that is known to be broken by this change.

The Rails developers apparently do not consider this a bug in ActiveSupport, but a bug in the libraries that use ActiveSupport.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文