I have a syntax issue I'm trying to sort out. I'm just trying to check if a controller/action is loaded, and if so do something, and if not do something else, seems simple. This gives me an error:
<% if (:controller => 'home', :action => 'index') do %>
<div class="header">
<% else %>
<div class="header-2">
<% end %>
Can someone assist me with the syntax issue here? Thank you!
You have to modify the if clause like this:
<% if controller_name == 'home' && action_name == 'index' %>
Additionally, if have to call this more than once, I'd suggest you define a helper.
application_helper.rb
def home_index?
controller_name == 'home' && action_name == 'index'
end
This way your code will be a lot more readable:
some_view.html.erb
<div class='<%= home_index? ? "foo" : "bar" %>'>
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