url = if url
if url.is_a? String
url
else
routes.generate url
end
else
routes.generate :controller => text
end
unless text.is_a? String
text = t text
end
active = request.request_uri == url
"<li #{'class="active"' if active}>#{ link_to text, url }</li>"
Would using url_for() not save you a lot of hassle generating that url?
Thanks Michael, url_for was what I was looking for in place of
manually grabbing the router. But why do you think that would change
the line you quoted?
routes = ActionController::Routing::Routes
unless url.is_a? String
if url[:controller]
url = url_for url
else
url = url_for :controller => text
end
end
unless text.is_a? String
text = t text
end
active = request.request_uri == url
"<li#{' class="active"' if active}>#{ link_to text, url }</li>"
unless url.is_a? String
if url[:controller]
url = url_for url
else
url = url_for :controller => text
end
end
unless text.is_a? String
text = t text
end
active = request.request_uri == url
content = link_to text, url
if block_given?
content << yield
end
"<li#{' class="active"' if active}>#{content}</li>"
end
end
Thomas
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.