I have Rails app with some models, frontend and administration with rails_admin. I have these rails_admin settings:
# Config/initializers/rails_admin.rb
RailsAdmin.config do |config|
...
config.included_models = %w[ User Page Event Link Slide Main Partner ]
...
end
But it's not working, it show only Events, Links, Pages. I do not know where I did mistake.
Are you using CanCan with rails admin?
Maybe you haven't set the ability model to make them manageable.
Or maybe you haven't restarted your server.
Related
I'm trying to use the Mobility gem with Rails Admin.
I am able to edit fields through the Rails Admin interface (like the impact_description of a Ngo model) and it correctly changes the translation tables:
But the problem is, the Rails Admin interface does not show the correct translation (it is showing in pt-BR, even when the app is in english):
Has anyone sucessfully integrated Rails Admin with the Mobility gem? Thanks for the attention
EDIT:
In my rails_admin.rb (initializer) I have the regular configurations for all actions (only changing new):
config.actions do
dashboard # mandatory
index # mandatory
new do
except [RewardRule, SuggestedFeed]
end
export
import
bulk_delete
show
edit
# delete
clone
show_in_app
## With an audit adapter, you can add:
# history_index
# history_show
end
And for the Ngo model I don't have any custom configuration, only that it is included on the Rails Admin models:
# rails_admin.rb
config.included_models = [..., Ngo, ...]
So I was able to do it after some research in the Rails Admin api.
For this to work on the Ngo model in the show action, for example, I did:
config.model Ngo do
show do
fields do
formatted_value{ bindings[:object].send(method_name) } # this calls the mobility method instead of getting the plain attribute, so it will translate on the admin.
end
end
end
In this case, all the fields will be calling the original method name, instead of the plain attribute. So for example, in my case, it will be calling ngo.impact_description, which will get the field translated, instead of reading the plain attribute ngo[:impact_description], which will always be in the default language.
As an admin I have a specific role
I want to see and switch event for object
Depends on my role
Inspired by activeadmin_addons and its Enum Integration I want to make similar functionality for AASM by letting diffent admin users change events depending on their abilities/roles for specific events/statuses in model.
Taken from here, please see this link for additional files you need
Prequestites:
Gem: ActiveAdmin,
Gem 'active_admin_role', both are installed and working AdminUser model with current_admin_user setup (or similar to your app).
Tested with Rails 5.1.3.
After you finish and deploy/run server you must "Reload" Permissions in admin and enable "event_update" for manager or other than "super_admin" roles.
Smaller addons you'll need to do:
(in addition to below attached files)
In your AdminUser model add:
include CanCan::Ability
include ActiveAdminRole::CanCan::Ability
In your table_for (is where you render columns of data):
column 'Our Status' do |auction|
render 'admin/auctions/event_change', auction: auction
end
In initializers/active_admin.rb or whenever you want
ActiveAdmin::ResourceController.class_eval do
protected
def current_ability
# Match to your current admin user
#current_ability ||= Ability.new(current_admin_user)
end
end
also make sure your config:
config.authorization_adapter = ActiveAdmin::CanCanAdapter
config.authorization_adapter = ActiveAdmin::CanCanAdapter
config.cancan_ability_class = 'Ability'
Pardon me if I forgot something, let me know if you have any question or problem !
I have an role column in my User model and I want to prevent someone from accessing the rails_admin routes if they don't have an admin flag. Since the RailsAdmin::MainController doesn't inherit from ApplicationController I'm not sure how I can insert this check before the view loads.
I'm not keen on creating a new Admin model as per the devise docs. I would like to use the same user account.
Does anyone have any suggestions? =)
You can define from which controller your rails admin will inherit by defining it in the config/initializers/rails_admin.rb file like this:
RailsAdmin.config do |config|
config.parent_controller = '::ApplicationController'
end
And also i recommend using a gem to handle authorization, cancancan or pundit will handle nicely your use case.
I am customizing Rails Admin : https://github.com/sferik/rails_admin , i need to disable/hide "Add new" option for some model.
Any help will save lot time for me. Thanks in advance
I use the following to achieve this on a specific model. Hopefully, this helps:
config.actions do
new do
except ['Some Model']
end
end
The answer is in the configuration documentation for actions. By default, all actions are possible, including new. To customize the possible actions, in config.actions in config/initilizers/rails_admin.rb, list all the actions you want to support, leaving out the ones you don’t want to support. For example, here is a config block that allows all of the default actions except for new:
# config/initilizers/rails_admin.rb
RailsAdmin.config do |config|
config.actions do
# root actions
dashboard
# collection actions
index
# `new` is NOT allowed
export
history_index
bulk_delete
# member actions
show
edit
delete
history_show
show_in_app
end
end
To have multiple models, you must put each model in single quotes. For example, consider the following configuration:
config.actions do
dashboard
index do
except ['Address']
end
new do
except ['Address', 'Employee', 'Setting']
end
export
show
edit do
except ['Employee']
end
end
This means that:
Addresses are not included on the navbar on the left
You cannot add a new address employee or setting with the "add new" button
There is no pencil icon in the index view for Employees for editing.
If you had a User model you could see it in the navbar, edit it, and add a new one on the index page.
You can export every model, but not bulk delete them.
Implemented it with Cancan. You can refer to above answer to do it in rails admin way.
URL : https://github.com/sferik/rails_admin/wiki/CanCan
I have a problem. In my app I am using rails_admin gem. Everything is good except one thing. For some models I want to make possible only to delete them. Is there an easy way to do this?
In your rails_admin.rb file, you can add the default actions for your models in wich you can add exceptions as shown here.
Here is an exemple :
config.actions do
dashboard # mandatory
index # mandatory
new do
except ['SomeModel']
end
export
bulk_delete
show
edit do
except ['SomeOtherModel']
end
delete
show_in_app
end
Here is the link to the rails_admin documentation about actions : https://github.com/sferik/rails_admin/wiki/Actions
try changing in the file: config/initilizers/rails_admin.rb you can comment out the actions that you don't want to allow!
You can do this using CanCan: https://github.com/sferik/rails_admin/wiki/Cancan
add this to your ability.rb file:
cannot :manage, Model # disable all actions for this model
can :destroy, Model # enable only to remove