P
P
Piranis2014-06-11 03:16:12
Ruby on Rails
Piranis, 2014-06-11 03:16:12

Rails add class="active" when url is within the same controller (:resources)?

This helper is walking on stack overflow.

def current_link_to label, path
  link_to label, path, class: (current_page?(path) ? "active" : nil)
end

Help me as a stackoverflow programmer to add a check for url and controller matches.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Viktor Vsk, 2014-06-11
@Piranis

if params[:controller] == "MyController"

P
Piranis, 2014-06-11
@Piranis

 Mistake:

No route matches {:action=>"index", :controller=>"welcome"}
Extracted source (around line #13):
10

   			%h1.logo Флайда
   			%ul.menu
   				%li
   					= current_link_to 'Главная', root_path

says no such routes for root_path and correctly says the following in routes.rb:
resources :services
  root :to => 'welcome#hi'
  get 'contacts' => 'welcome#contacts'

That is, there is such an action hi for the welcome control

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question