I haven't been able to find a clear answer in the ActiveAdmin docs, or elsewhere. Is there a way to dynamically set the title of a panel or sidebar? For example, I need to have the name of the resource that I'm filtered to included in the title. Is that possible?
panel "#{resource.name}", class: "panel_with_resource_name" do
.....
end
or maybe you are looking for this?
controller do
before_action {
#title = " #{Model.find(params[:your_object_id]).try(:whatever_params)}"
}
end
or
controller do
def whatever_action
#title = "this is"+resource.name
end
end
then in view
whatever_action:title=> #title do
.....
end
Related
I've looking for info about how can I modify the title of an ActiveAdmin Custom page, but nothing works. The solution I found only works for standard ActiveAdmin pages.
For example, my Report page
ActiveAdmin.register_page "report" do
controller do
before_action { #page_title = "Generación de reportes" }
end
menu label: 'Generación de reportes'
content do
render partial: 'report'
end
end
Shows the standard title, which is the same string with which it was registered.
Is there a way I can customize the title, so I can put something like "Generación de reportes" for example?
In your provided link, you have the following options to modify the title of a page:
content 'title': Proc.new {
#page_title = 'Your title'
} do
...
end
or the other option, according the docs:
content title: "Your Title" do
...
end
According the docs, you have to see "Image or link in the title bar of a custom page" in the same link!
You using before_action when register a controller, but in the provided code, you are registering a page.
Hope this helps!
How can I replace the Link text on active-admin navbar for a model?
I have a model: OpportunityConsultantPairing, which I'm registering in active-admin as follow:
ActiveAdmin.register OpportunityConsultantPairing do
controller do
before_filter { #page_title = "Project Pairings" }
end
end
setting #page_title only changes the Title, what I want to do however is to change both the title, as well as the navbar-link text as shown below:
How can one go about this? thank you.
Try this
ActiveAdmin.register OpportunityConsultantPairing do
menu label: "Project Pairings"
controller do
before_filter { #page_title = "Project Pairings" }
end
end
for more info check here:- http://activeadmin.info/docs/2-resource-customization.html
Try this
ActiveAdmin.register AdminUser, as: 'User' do
# code...
end
Navigation label will be changes as 'user/users' instead of 'admin_users'
routes will be configured automatically as '.../admin/users' instead of '.../admin/admin_users'.
I have a navbar that is placed in the /views/layouts/application.html.erb and in there I place the #buy and #sell variables which get the latest bitcoin price. They are currently placed in the /welcome controller so the prices only show when in the welcome controller. If I navigate to another controller, the bar just becomes empty.
#buy = coinbase.buy_price
#sell = coinbase.sell_price
That is the code that is currently placed in the welcome controller. I want it to be available to the navbar regardless of what controller the user is in. Any help would be great!
place it in the application controller and use a before action
before_action :set_prices
def set_prices
#buy = coinbase.buy_price
#sell = coinbase.sell_price
end
Two ways:
Write the code in application_controller as before_filter, and use the variables in nav bar.
before_filter :prices
def prices
#buy = coinbase.buy_price
#sell = coinbase.sell_price
end
Write the code in application.html.erb, just before the nav bar code:
<% #buy = coinbase.buy_price %>
<% #sell = coinbase.sell_price %>
And use them directly.
I need to add a few links to certain pages of the application in the ActiveAdmin pages. I can do this using sidebars, but I'll have to repeat the code for each of my resources. Is there anyway of adding custom links to the header ? Or define a sidebar that will appear for all resources ?
I also wouldn't want to overlook setting config.site_title_link in initializers/active_admin.rb.
I'm pretty sure it takes a symbol representing the name of a route from your application, for example:
config.site_title_link = :root
would link the site title to your application's root_path.
Thanks #phoet ! Implemented it by overriding the HeaderRenderer instead:
module ActiveAdmin
module Views
class HeaderRenderer
def to_html
title + global_navigation + application_link + utility_navigation
end
def application_link
link_to('Back to Application', root_url)
end
end
end
end
i think there is no build-in way to do it, but you can override the render-logic in the TabsRenderer (2.2) / TabbedNavigation (3.0):
def render_menu(menu)
content_tag :ul, :id => #options[:id] do
menu.items.collect do |item|
render_item(item)
end.join.<<('your_custom_stuff').html_safe
end
end
I have a small question regarding rails. I have a search controller which searches for a name in database, if found shows the details about it or else I am redirecting to the new name page. Is there anyway after redirection that the name searched for to automatically appear in the new form page?
Thanks in advance.
You can use the ActionController::Flash to pass data between actions.
def search(searchedName)
# perform search on DB
flash[:searchedName] = searchedName
redirect_to new_name
end
def new_name
end
new_name.html.erb:
<% if flash[:searchedName] %>
<%= text_field_tag flash[:searchedName] %>
<% end %>
Well, let's say you are saving this 'name' entered by user on a variable named #name.
So, on the controller that do the action of search, you did something like:
if #name
...#action if the name was found
else
session[:name] = #name
...#here is the action you did to redirect
On the declaration of the method called (you said it was 'new') :
def new
#name = session[:name] if session[:name] #I don't know exactly if the condition is this one,
#but you have to confirm that the session was instatiated
session.delete(:name) #to don't let garbage
...#continuous the action of show the new page
#and on the page you have access to a variable #name, that have the name searched before.