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'.
Related
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
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!
I have to add view for custom action which is member action, and want to display association records on it. Is there way to add custom view instead of just adding html.erb in admin's view folder?
I dont want to add or create html files but by using the active admins helpers.
The member action in nothing else like a controller action, thats mean you can do the same things in it.
You can use thinks like:
render text: "Hello world!"
Or if you want a complex markup:
message1 = "Hello"
#message2 = "world!"
view = Arbre::Context.new(message: message, self) do
h1 do
span message
span #message
end
end
render body: view.to_html # or .to_s
You can use the following code for the render html for rails 4.1:
render html: '<html><body>Some body text</body></html>'.html_safe ## Add html_safe
But, if you use rails 4.2, so you can use the following:
render text: '<html><body>Some body text</body></html>'
I think the following answer is very useful for your question.
Ended up with adding the following in html.erb file in admin/user/messages.html.erb
<% view = Arbre::Context.new({messages: #messages, user: #user}, self) do
panel "Sent Messages" do
paginated_collection(messages, download_links: false) do
table_for collection do
column :id
column :content
end
end
end
end
%>
<%= view.to_s %>
Depending on your namespace (ActiveAdmin is on /admin in my case) you can create the folder app/views/admin in the same way you would in the rest of your application.
For example, if you have a resource User and an action apply_discount
ActiveAdmin.register User do
member_action :apply_discount, method: [:get, :put] do
if request.get?
render :apply_discount
else
# TODO ...
end
end
end
you could put your ARBRE view file into app/views/admin/users/apply_discount.html.arb -> notice the extension is ARB, not ERB - though ERB should work too according to the docs
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 am working with ActiveAdmin and need to make customizations to some views and have come across a couple of scenarios I feel I am doing wrong.
I am adding an additional table to a show view (comments on Posts). This requires me to rewrite the whole attributes table and then add my panel. Is there a way to customize views without losing the default content?
I would also like to add a table of associated items on the show view which doesn't need to be customized is there any way to include the default tale that would normally be on the index view with default actions and paging?
After digging in the source code of Active Admin, I've found a way to patch this
show do
default_main_content
panel "Your Added Stuff" do
# Add stuff here
end
end
Of course this is undocumented and maybe considered a hack, but unless any other solution exists, it works.
Note: To do this in the form action (new and edit):
form do |f|
f.inputs
# Other inputs here
f.actions
end
Instead of using default_main_content, you could also just loop through the columns on the model like so:
ActiveAdmin.register Ad do
show do
attributes_table do
default_attribute_table_rows.each do |field|
row field
end
# Custom bits here
end
end
end
A couple areas of the documentation might help you:
See Customize the Show Page, Customizing the Index Page, Customizing the Form, and Custom Pages. An example of customizing a show screen:
ActiveAdmin.register Ad do
show do |ad|
default_main_content
h3 ad.title
end
end
See Custom Action Items in the Custom Controller Actions section of the documentation. An example:
action_item :only => :show, :if => proc{ current_admin_user.super_admin? } do
"Only display this to super admins on the show screen"
end
NB default_main_content does not exist in the documentation anymore, yet it works fine.
Just figured that out myself:
For the default table index page you can do something like this
index do
h1 "Hello World"
p "get more content"
instance_eval(&default_table)
end