如何在 rails_admin 中添加标签模型(ActsAsTaggableOn)? [英] how add tag model (ActsAsTaggableOn) in rails_admin?

查看:43
本文介绍了如何在 rails_admin 中添加标签模型(ActsAsTaggableOn)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我安装了 rails admin 并将所有模型包含在 rails admin 的活动记录中,

I install rails admin and include all model in active record in rails admin,

第一次,当安装 rails admin 时显示这个错误

first time, when install rails admin display me this error

NoMethodError in RailsAdmin::MainController#index

undefined method `per_page_kaminari' for #<ActiveRecord::Relation:0x00000006713e18>

并通过添加此配置来修复它

and fixed it by added this configure

Kaminari.configure do |config|
    config.page_method_name = :per_page_kaminari
end

在项目中安装acts_as_taggable_on gem时,rails admin没有在其中添加标签模型(我在其他模型中添加了字段tags_list),但我想在rails admin中添加标签模型来管理标签(索引、创建、编辑和销毁)..

when install acts_as_taggable_on gem in project, rails admin did't add tag model in it ( i added field tags_list in other model), but i want to add tag model in rails admin to manage tags (index,create,edit and destroy)..

我添加了这一行

config.included_models = ['ActsAsTaggableOn::Tag'] 

在 rails_admin.rb 中,它在仪表板中显示我的标签模型,但是当打开列表标签时,它再次显示我这个错误

in rails_admin.rb and it display me tag model in dashboard, but when open list tags, it display me again this error

NoMethodError in RailsAdmin::MainController#index

undefined method `per_page_kaminari' for #<ActiveRecord::Relation:0x00000006713e18>

我应该怎么做才能在 rails admin 中添加标签模型并管理标签?!

what should i do to add tag model in rails admin and manage tags ?!

推荐答案

我不得不在这里解决同样的问题.我使用了 gem 'rails_admin_tag_list' 但 ruby​​gem 的最新版本没有针对 rails 4 更新(不支持 RailsAdmin 属性).所以你需要从 master 那里得到一个包含 fix.

I had to solve the same issue here. I used the gem 'rails_admin_tag_list' but latest version from rubygem is not updated for rails 4 (doesnt support RailsAdmin Property). So you need to get the one from master that include the fix.

gem 'rails_admin_tag_list', git: 'https://github.com/kryzhovnik/rails_admin_tag_list.git', branch: 'master'

确实补充:

config.included_models = ['YourModel', 'ActsAsTaggableOn::Tag']

class YourModel < ActiveRecord::Base
  acts_as_taggable # dont add attr_accessible stuff since we're in rails 4
end

然后选择标签列表的配置:

then choose the config for tag list:

config.model 'YourModel' do
  configure :tag_list  do
    partial 'tag_list_with_autocomplete'
  end
  exclude_fields :body, :locale, :base_tags, :tags
end

这篇关于如何在 rails_admin 中添加标签模型(ActsAsTaggableOn)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆