How are you.
I have just installed padrino framework admin panel.
And it shows several tabs in admin module.
I want to rename the labels. but how to do it?
This is view side code
<%= link_to project_module.human_name, url(project_module.path) %>
Here I can't set human_name of project_module.
And this is module definition in application.rb
access_control.roles_for :admin do |role|
role.project_module :accounts, '/accounts'
role.project_module :venues, '/venues'
role.project_module :shows, '/shows'
end
Now tabs labels are Accounts, Venues, Shows.
how to set them as Users, MyVenues, MyShows?
Thanks
Just seemed to hit this issue tonight as well. It seems that this is a slight bug that is in the core Padrino framework.
The standard navigation logic out of the box will never produce a proper localized text. It renders the output of function .humanize
https://github.com/padrino/padrino-framework/blob/8bd3796d45eae5e3f7dc52316c8c25c44563f8cd/padrino-admin/lib/padrino-admin/access_control.rb#L176
At best, the humanize function will upcase your text. See https://apidock.com/rails/String/humanize
You can replace the human_name reference with the I18n.t() localizable function:
%ul.nav.navbar-nav.pull-left
- project_modules.each do |project_module|
%li{:class => "navbar-module #{('active' if request.path_info =~ /^#{project_module.path}/)}"}
=link_to I18n.t(project_module.name), url(project_module.path)
See http://padrinorb.com/guides/features/localization/ for reference.
One note, the navigation is not model aware, so your translated text will need to be right under the locale reference in the yml file.
Ex.
en:
accounts: Users
venues: MyVenue
shows: MyShows
This should do the trick. Let me know if you have any questions.
Related
There are 20 different buttons to expect and needs to be clicked through to expect and verify the urls inside the code. I have tried different ways to implement my tests but they are failing.
I'm trying something like:
page.all(:class => 'action red').each do |button|
c = button.find(:class => 'action view red')
c.click
page.driver.browser.switch_to.window(#new_window)
expect('some element on those 20 different browsers sessions before closing them')
page.driver.browser.close
end
end
I'm getting this error:
ArgumentError: invalid keys :class, should be one of :count, :minimum,
:maximum, :between, :text, :visible, :exact, :match, :wait
Any can help me in the code how to perform get the elements of all the 20 buttons, store them and click them to expect the url each of them before closing it
Your "buttons" aren't buttons - since they are <a> elements they are actually links, styled to look like buttons.
Assuming that clicking each of these links actually opens a new window (since you're attempting to switch to a new window) then the code would be something like
page.all(:link, class: ['action', 'red']).each do |link|
win = page.window_opened_by { link.click }
page.within_window(win) do
expect(page).to ... # whatever you need to expect
end
win.close()
end
Note this doesn't use any driver specific (.driver.browser...) methods - you should stay away from them whenever possible since they are generally a sign you're doing something wrong. Additionally, the :class option wasn't universally available on all of Capybaras builtin selector types until v2.10, so you will need to be using a newer version of Capybara for that.
I have to logout a user(admin_user) if the user(admin_user) is not using the application for 15 minutes. How it can be done? I have tried installing activeadmin in my vendor and overriding it(putting devise.rb inside initializers folder inside vendor and write set timeout it did not work), but I don't know how that works. Please help me. I cannot write it in devise.rb as it is done via normal login(user).
Also I have one more query, how the main navigation bar can be changed in activeadmin? I need two menu one in main navigation bar and according sub navigation. Is this achievable through activeadmin?
Jut use config.timeout_in = 15.minutes in your devise.rb initializer.
Active admin has nothing to do with that.
I don't know whether this is the correct way of getting layouts, but I found the solution creating my_navigation resource in active admin.
class MyNavigation < ActiveAdmin::Component
def build(namespace, menu)
if current_admin_user
render :partial => "/layouts/admin_header"
else
render :partial => "/layouts/company_admin_header"
end
end
end
I need to use part of my application in iframe on another page. So I need to remove layout on these pages.
I added to ApplicationController
layout :current_layout
def current_layout
if params[:layout] == false.to_s
false
else
'main'
end
end
This works until user click on any link in navigation. So I need to add to every link_to in this part of application something like:
link_to 'store', store_path(params.merge({layout: params[:layout]})
I am wondering that maybe I can refactor that and maybe remove this params.merge from every link?
You could try something like this:
def my_path_helper(string, path_type, params)
link_to(string, polymorphic_path([path_type], params.merge({layout: params[:layout]})))
end
See the docs for polymorphic path here and also this answer that provides an example.
Is this what you were looking for?
I'm just getting used to Middleman and Ruby in general. What's the best way to generate a navigation with active states?
In the current version of MM (2.x, though 3.0 is close), you can do it with the following additions to config.rb and some tweaks in your nav file(s). Here is a working version in case I leave out some critical bits:
First create a helper function:
helpers do
def nav_active(page)
#page_id == page ? {:class => "Active"} : {}
end
end
Then, in the nav bar include file (in this case its a haml file) you can use the nav_active helper as follows:
#HeaderNavigationBar
%ul
%li{nav_active("index")}= link_to t('top_navigation.home'), t('paths.index')
%li{nav_active("pricing")}= link_to t('top_navigation.pricing'), t('paths.pricing')
%li{nav_active("faq")}= link_to t('top_navigation.faq'), t('paths.faq')
The net result of this is to add the class "Active" to the link in the nav bar when the page is building built for this page. I.e. if the page is a file called "index" then the #page_id will be "index" and that link will have the Active theme.
To complete the example, here is the excerpt from the scss style partial that defines active:
&.Active {
font-weight: bold;
}
In a later version of the header file, we actually removed the link when on the active page. It looks something like - which could clearly be tidied up, but FWIW :D:
%li{nav_active("index")}
-if "index" == #page_id
= t('top_navigation.home')
-else
= link_to t('top_navigation.home'), root()
... (etc)
Note that all the t('stuff') has to do with translation functions for i18n. You can ignore that. I didn't want to make the example syntactically wrong by trying to remove them.
Hope this helps - also see the forum at http://forum.middlemanapp.com/.
Here’s a new gem for marking up a current link in Middleman with aria-current (which you can then use to style off of): https://github.com/thoughtbot/middleman-aria_current
I have the same problem, as in this question. Did anybody find any solutions for this?
So I can't do like this:
flash[:notice] = "Successfully created #{#template.link_to('product', #product)}.
or like this:
#template.title("Page title is here.")
It worked perfectly in Rails 2.3. The main idea is to find out, how to use helper methods directly from conrollers, not from views.
Thanks.
You're doing it wrong.
First, you should setup the title of a page inside the view, not in your controller.
You can simply place a call to the title helper within your view file.
About the link, flash shouldn't contain HTML. However, you can create the link manually.
flash[:notice] = %Q{Successfully created product.}
I ran into this same problem as well and found that you can use the view_context method.
API documentation here: http://api.rubyonrails.org/classes/AbstractController/Rendering.html#method-i-view_context