小马和续集的协会有冲突吗?
我在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不管您相信与否,这是由 ActiveSupport 问题引起的。您应该下降到 ActiveSupport 3.0.3 或通过以下方式手动要求默认的 ActiveSupport 变形:
基本上,在 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:
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.