rails-admin

Rails admin has_many :through relationship causing infinite rendering of templates when editing resource

我的梦境 提交于 2019-12-12 04:53:51
问题 I have a rails app with a has_many :through model like so: class Blog < ActiveRecord::Base has_many :blog_categorizations, dependent: :destroy has_many :categories, :through => :blog_categorizations accepts_nested_attributes_for :categories, allow_destroy: true end class Category < ActiveRecord::Base has_many :blog_categorizations, dependent: :destroy has_many :blog, :through => :blog_categorizations accepts_nested_attributes_for :blog, allow_destroy: true end class BlogCategorization <

rails_admin plural field names

寵の児 提交于 2019-12-12 04:39:49
问题 I'm using rails_admin in an app and I'm getting an unexpected error. In a certain model, I have a field called *_status_id. When trying to edit that model in rails_admin, I get this error: undefined method `*_statu_id' Obviously, rails_admin thinks my resource is plural, when it is not. Is there a way of letting Rails/rails_admin know how to use this resource properly? 回答1: "status" has an irregular plural; one which Rails doesn't know about automatically. In config/initializers/infelctions

Using roll your own authentication with the rails_admin gem

倾然丶 夕夏残阳落幕 提交于 2019-12-12 01:25:45
问题 How do you implement authentication with the rails_admin gem when you are not using devise e.g. you have rolled your own authentication? 回答1: In config/initializers/rails_admin.rb include a config.authenticate_with block and place your authentication logic there. It should raise an exception if the user is not authorised to use rails_admin. Here is a simple example: RailsAdmin.config do |config| config.authenticate_with do raise 'You must be admin' unless signed_in? && current_user.admin? end

How do I use CanCan with rails admin to check for ownership

家住魔仙堡 提交于 2019-12-12 01:05:59
问题 When a user in my app isn't an admin user i want to only let them see the fields that they have ownership of. Is there a so set can :see or something like that on a per field basis so that it displays just the fields that that use "can see", or should I have an ability called can :oversee to state that they can see everything instead. I suppose it's much easier to just check if the user is admin or not in rails admin, so where set rails admin to only pull the current user's records. 回答1: With

Display custom label for User in rails_admin paper_trail history

╄→尐↘猪︶ㄣ 提交于 2019-12-11 23:37:37
问题 When I go to a paper_trail history page in rails_admin, I see User objects in the User column ( #<User:0x007f59a9... ). Is there a way to configure this to use one of the User attributes? I thought I could use object_label_method but I don't seem to be having any luck. Update: I thought this was purely a display issue but paper_trail is actually storing Strings like #<User:0x007f59a9... in the whodunnit column of the versions table rather than IDs. I have overridden user_for_paper_trail in

RailsAdmin custom action to restore soft deleted records

牧云@^-^@ 提交于 2019-12-11 14:01:37
问题 I am using Rails 4.1.14 with rails_admin 0.8.1, mongoid 5.0 and mongoid_paranoia. I created RailsAdmin custom action to restore soft deleted Users. class Restore ... register_instance_option :controller do Proc.new do object.restore ... end end end But I keep getting User with id '5695997df5740c17b0000002' could not be found From my develoment.log Started GET "/admin/user/5695997df5740c17b0000002/restore" for 127.0.0.1 at 2016-01-12 16:35:04 -0800 Processing by RailsAdmin::MainController

Rails_admin redirect to 404

风格不统一 提交于 2019-12-11 12:16:42
问题 I have set up rails_Admin gem for my app. I want to redirect to a 404 page if the user is not an admin. Here is the code below - RailsAdmin.config do |config| config.authorize_with do |controller| unless user_signed_in? && current_user.admin? #redirect to 404 - I need the code for this! end end end How do I do it? 回答1: You can just do: raise ActionController::RoutingError.new('Not Found') 来源: https://stackoverflow.com/questions/23892782/rails-admin-redirect-to-404

Getting Paper_trail + Rails_admin + Devise with Multiple 'user' models

女生的网名这么多〃 提交于 2019-12-11 11:06:15
问题 I am developing an app in Rails 3, currently I use Devise as the login and Rails_admin as the admin panel with Paper_trail tracking all changes made by 'user' model... Problem is I have two user models, User and Admin. So a line of code in rails_admin.rb (initiliazer) to setup Paper_trail to track history: config.audit_with :paper_trail, User Is there any way to have paper_trail monitor changes made by both User and Admin, or can it only follow one model? I notice that even when it is set

filter export result by email in rails admin

元气小坏坏 提交于 2019-12-11 10:06:40
问题 I am trying to filter the the data to be exported in the csv file that rails admin will generate but I want to only export data for a particular email so that no other users can export another person's data. Is there a way to do this? 回答1: You will have to implement your own export action to do this. I won't be that hard since you can just copy paste the existing one found in https://github.com/sferik/rails_admin/blob/master/lib/rails_admin/config/actions/export.rb In your own project root

how add tag model (ActsAsTaggableOn) in rails_admin?

倖福魔咒の 提交于 2019-12-11 07:53:50
问题 I install rails admin and include all model in active record in 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 when install acts_as_taggable_on gem in project, rails admin did't add tag model in it ( i added field tags