Thanks Norman, I will use the helper

Best regards

On Dec 25, 11:50 pm, Norman Clarke <[email protected]> wrote:
> BTW, if all you want to do is add the class "active" to current links,
> rather than using the default block in "link_to_unless_current", you may
> wish to simply wrap the "link_to" method and use the "current_page?" method
> directly, which I think is a cleaner way to accomplish what you're trying to
> do:
>
> def nav_link(name, options = {}, html_options = {}, &block)
>   if current_page?(options)
>     html_options[:class] ? html_options[:class] <<  " active" :
> html_options[:class] = "active"
>   end
>   link_to(name, options, html_options, &block)
> end
>
> --Norman
>
> On Fri, Dec 25, 2009 at 1:22 PM, G. Sobrinho 
> <[email protected]>wrote:
>
>
>
> > This doesn't work because link_to_unless_current expects the result of
> > block and using "-" doesn't return the output to the block.
>
> > On Dec 23, 6:09 pm, Rhett Sutphin <[email protected]> wrote:
> > > Hi Gabriel,
>
> > > On Dec 23, 2009, at 1:53 PM, G. Sobrinho wrote:
>
> > > > Hi,
>
> > > > I'm using HAML on my projects and I having a trouble with
> > > > link_to_unless_current.
>
> > > > Reading the Rails documentation you can use:
>
> > > > <%=
> > > >   link_to_unless_current("Comment", { :controller => 'comments',
> > > > :action => 'new}) do
> > > >     link_to("Go back", { :controller => 'posts', :action => 'index' })
> > > >   end
> > > > %>
>
> > > > I want a similar behavior, like this:
>
> > > > = link_to_unless_current('Contact', contact_index_path) { link_to
> > > > 'Contact', contact_index_path, :class => 'active' }
>
> > > > Not that this works but the line is too big. To make the line more
> > > > readable i'm trying to use:
>
> > > > = link_to_unless_current('Contact', contact_index_path) do
> > > >   = link_to 'Contact', contact_index_path, :class => 'active'
>
> > > Try:
>
> > > = link_to_unless_current('Contact', contact_index_path) do
> > >    - link_to 'Contact', contact_index_path, :class => 'active'
>
> > > Note the '-' instead of '=' in the second line.  It means that that
> > > line should be executed, but the result shouldn't be appended to the
> > > page.  This is equivalent to the ERB you included above and the first
> > > (single line) haml version.
>
> > > Rhett
>
> > > > But this create a unexpected "7" on the source. If i'm outside contact
> > > > page this works fine. But if i'm on contact page (which will use the
> > > > block) the rendered HTML render this:
>
> > > > <ul>
> > > > <li><a href="/">Home</a></li>
> > > > <li><a href="/pages/about-us">About US</a></li>
> > > > <li>
> > > > <a href="/contact" class="active">Contact</a>
> > > > 7
> > > > </li>
>
> > > > </ul>
>
> > > > It's a HAML related issue or I need to do it in another way?
>
> > > > --
> > > > Cordialmente,
>
> > > > Gabriel Sobrinho
> > > > Diretor de desenvolvimento
>
> > > > Hite - Comunicação Digital e Mídia Interativa
> > > >http://www.hite.com.br/
>
> > > > +55 31 8775 8378
>
> > > > --
>
> > > > You received this message because you are subscribed to the Google
> > > > Groups "Haml" group.
> > > > To post to this group, send email to [email protected].
> > > > To unsubscribe from this group, send email to
> > [email protected] <haml%[email protected]>
> > > > .
> > > > For more options, visit this group athttp://
> > groups.google.com/group/haml?hl=en
> > > > .
>
> > --
>
> > You received this message because you are subscribed to the Google Groups
> > "Haml" group.
> > To post to this group, send email to [email protected].
> > To unsubscribe from this group, send email to
> > [email protected] <haml%[email protected]>.
> > For more options, visit this group at
> >http://groups.google.com/group/haml?hl=en.

--

You received this message because you are subscribed to the Google Groups 
"Haml" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to [email protected].
For more options, visit this group at http://groups.google.com/group/haml?hl=en.


Reply via email to