小编Den*_*ive的帖子

rails3中没有命名路由的远程form_tag

什么是使这个实际上异步发布的正确咒语?

form_tag :controller => :magic, :action => :search, :method => post, :remote => true do
Run Code Online (Sandbox Code Playgroud)

method = post和remote = true只是在url的末尾被压扁而不是实际上使它成为ajax帖子.

ruby ruby-on-rails ruby-on-rails-3

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

Rails:独特用户的三条最新评论

我将在命名范围中放入什么:by_unique_users以便我可以执行Comment.recent.by_unique_users.limit(3),并且每个用户只能获得一条评论?

class User
  has_many :comments
end

class Comment
  belongs_to :user
  named_scope :recent, :order => 'comments.created_at DESC'
  named_scope :limit, lambda { |limit| {:limit => limit}}
  named_scope :by_unique_users
end
Run Code Online (Sandbox Code Playgroud)

在sqlite named_scope:by_unique_user,:group =>"user_id"工作,

但是它会在postgres上出现问题,postgres部署在生产PGError:ERROR:列"comments.id"必须出现在GROUP BY子句中或用于聚合函数

ruby sqlite postgresql activerecord ruby-on-rails

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