ActiveAdmin custom views which retain the ActiveAdmin layout
Problem solved. Just add layout 'active_admin'
to your code :
controller do
layout 'active_admin' # <-- here
def index
@search = Page.includes(:translations).where("page_translations.locale='fr'").metasearch(params[:search])
@pages = @search.page params[:page]
end
def edit
@page = Page.find params[:id]
end
end
Customise layout (components ) for activeadmin
The activeadmin layout components are very easy to customize. What you need to do: Just define a module that opens ActiveAdmin::View.
you can have a custom_activeadmin_components.rb in initializers or admin directory where you defined all of your activeadmin resources. I prefer to put it in the directory where your activeadmin resources are. Then override any module you want:
here is a sample:
module ActiveAdmin
module Views
class Header < Component
def build(namespace, menu)
super(:id => "header")
@namespace = namespace
@menu = menu
@utility_menu = @namespace.fetch_menu(:utility_navigation)
build_site_title
build_global_navigation
build_utility_navigation
#you can add any other component here in header section
end
def build_site_title
render "admin/parts/logo"
end
def build_global_navigation
render "admin/parts/main_nav"
end
def build_utility_navigation
render 'admin/parts/language_options'
insert_tag view_factory.global_navigation, @utility_menu, :id => "utility_nav", :class => 'header-item tabs'
render 'admin/parts/branch_in_header'
end
end
module Pages
class Base
def build_page_content
build_flash_messages
div :id => :wizard_progress_bar do
render 'admin/parts/wizard_progress_bar'
end
div :id => "active_admin_content", :class => (skip_sidebar? ? "without_sidebar" : "with_sidebar") do
build_main_content_wrapper
build_sidebar unless skip_sidebar?
end
end
end
end
end
end
Custom index views with ActiveAdmin
I ended up doing this using a technique described on their Google Group, in which you just shove the user over to a custom action:
https://groups.google.com/d/msg/activeadmin/YgMzeYBXRno/GZ01Epyq5lcJ
Hacky, yes. I think this is a much needed feature, so hopefully someone can fork and add in support for the index view to take a block with custom content.
Rails 4 - ActiveAdmin layout is blank but application layout works for custom controller action
Well, now i know what was the reason.Looking through the logs clearly mentioned something about the layout and when i searched the code, i founded out that there was a code to override the BaseController of ActiveAdmin.i removed that code now and now its working the way i want.i am sharing the code below that was causing the problem...
###admin/custom_layout.rb
###XXXXXXXXXXXXXXXXXXXXXXX REMOVED THIS FILE ###########################
# module BaseControllerPatch
# def determine_active_admin_layout
# ##'activeadmin_custom_layout/application'
# 'active_admin'
# end
# end
# module ActiveAdmin
# class BaseController
# prepend BaseControllerPatch
# end
# end
Now i dont have any cusotm active_adin code and by default,its working perfectly without any need to add custom code.However, i want to add custom attributes in the body tag, which i can easily add in initializers/active_admin.rb
Hope this helps someone.
Custom active admin page with index action
make sure you have _index.html.erb
file
views/admin/myname/_index.html.erb
Rails activeadmin redirect to customized view page from customse action
You may try this:
ActiveAdmin.register User do
action_item :password_reset_action_item, only: :edit do
link_to 'Reset', password_reset_admin_user_path(id: user.id)
end
member_action :password_reset do
@user = User.find(params[id]) # tips: you can (& should) use `resource` to lookup records by id. it will save you a couple of lines when you integrate authorization adapters like cancancan/pundit
render 'active_admin/users/password_reset' # you may omit this line if your template and action names are equal
end
end
Active Admin custom 400, 500 error pages
into your routes:
match "/404", to: "errors#render_error"
match "/500", to: "errors#render_error"
build new controller called ErrorsController
class ErrorsController < ApplicationController
def render_error
exception = env["action_dispatch.exception"]
status_code = ActionDispatch::ExceptionWrapper.new(env, exception).status_code
@method, @message = if status_code == 404
["not_found", env["REQUEST_URI"]]
else
["server_error", "#{exception.message}\n#{exception.backtrace.join('\n')}"]
end
render status: status_code
end
end
then in your ApplicationController:
private
def not_found
raise ActionController::RoutingError.new('Not Found')
end
then create new view to show any html you want.
hope it helps you.
Related Topics
Ruby Copy a Paperclip Attachment from One Model to Another
Turn on Full Backtrace in Ruby on Rails Testcase
Rails Helper - How to Get a Helper to Give Me a '<Br/>' (Or Other Markup)
Ruby Not Finding New Version of Openssl
Is There a Solution to Bypass 'Can't Add a New Key into Hash During Iteration (Runtimeerror)'
Shorter Way to Pass Every Element of an Array to a Function
In Ruby How to Automatically Populate Instance Variables Somehow in the Initialize Method
Is There a Pry Debug Setup That Works with Ruby 2.0
How to Express 'Infinite Time'
No Implicit Conversion from Nil to Integer - When Trying to Add Anything to Array
Activeadmin Custom Views Which Retain the Activeadmin Layout
Calling a Sinatra App Instance Method from Testcase
Error Installing Ruby 2.6.7 on MAC Os - How to Resolve
You May Have Encountered a Bug in the Ruby Interpreter or Extension Libraries
Installing Libyaml for Ruby on a MAC Osx (Lion)