开发者

Set different primary key in Active Admin (Rails)

I'm using Active Admin as my interface for a rails project (client's request). The problem is... most of the tables in my client's database have primary key fields named 'something_id' instead of plain 'id'. This poses a big problem as Active Admin looks for an 'id' field and, since it doesn't find one, it basically crashes the page with an error:

Mysql2::Error: Unknown column 'buzz_articles.id' in 'order clause': SELECT  `buzz_articles`.* FROM `buzz_articles` ORDER BY buzz_articles.id desc LIMIT 30 OFFSET 0

I've tried running set_primary_key :articl开发者_开发技巧e_id in the resource, but it's not recognized.

Any help? Please??


This is a known issue that we're working on. To get around it, add a sort_order to your resource definition.

Example:

ActiveAdmin.register Post do
  config.sort_order = 'something_id'
end

I haven't tested this out personally, however it's been reported to work here: https://github.com/gregbell/active_admin/issues/148

Ticket on github for this issue: https://github.com/gregbell/active_admin/issues/235

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜