My problem is that I'm trying to do something like
current_page?(controller: 'tigers', action:('index'||'new'||'edit'))
which returns true when the controller is tigers and the action is either index, new, or edit.
The above does not throw an error, but only matches the first action.
Help!
More verbose, but works:
current_page?(controller:'bikes') &&
(current_page?(action:'index') ||
current_page?(action:'new') ||
current_page?(action:'edit'))
Less verbose, also works:
params[:controller] == 'bikes' && %w(index new edit).include?(params[:action])
%w() is a shortcut for building arrays of space delimited strings
You can also do something like this:
if current_page?(root_path) || current_page?(about_path) || current_page?(contact_path) || current_page?(faq_path) || current_page?(privacy_path)
Note: Do not leave blank space before parenthesis otherwise it won't work.
An alternative to using the current_page? method is to check the params hash directly:
params[:action] == ('index' || 'new' || 'edit')
Will return true if on index, new, or edit. You can also access the controller through params[:controller].
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With