Rails way to make a tag class active in view?


#1

for example 3 is in active state. right now all i can think of is in
each action, just set a variable like @active = ‘active’ or ‘’, but not
sure what to do with the span.

<ul>
  <!-- The link you call "active" will show up as a darker tab -->
  <li><a href="index.html">1</a></li>
  <li><a href="index.html">2</a></li>
  <li class="active"> <span>3</span> </li>
  <li><a href="index.html">4</a></li>
  <li><a href="index.html">5</a></li>
</ul>

#2

On Jun 1, 2007, at 10:55 AM, mixplate wrote:

  <li><a href="index.html">4</a></li>
  <li><a href="index.html">5</a></li>
</ul>

Assuming that the “index.html” would actually be based on the 1, 2,
etc.:

    <% for example in @examples %>
  • <%= link_to_unless_current example, example_path(example) do |text| content_tag(:span, text, :class => 'active') end %>
  • <% end %>

When @examples = [1,2,3,4,5]
and example_path(3) => “/example/3”

Gives:

Is that what you’re looking for? The link_to_if, link_to_unless,
link_to_unless_current helpers take a block that is passed the text
of the link when the condition isn’t satisfied for making the link.

-Rob

Rob B. http://agileconsultingllc.com
removed_email_address@domain.invalid


#3

(resending without being signed, sorry if the original shows up)
On Jun 1, 2007, at 10:55 AM, mixplate wrote:

  <li><a href="index.html">4</a></li>
  <li><a href="index.html">5</a></li>
</ul>

Assuming that the “index.html” would actually be based on the 1, 2,
etc.:

    <% for example in @examples %>
  • <%= link_to_unless_current example, example_path(example) do |text| content_tag(:span, text, :class => 'active') end %>
  • <% end %>

When @examples = [1,2,3,4,5]
and example_path(3) => “/example/3”

Gives:

Is that what you’re looking for? The link_to_if, link_to_unless,
link_to_unless_current helpers take a block that is passed the text
of the link when the condition isn’t satisfied for making the link.

-Rob

Rob B. http://agileconsultingllc.com
removed_email_address@domain.invalid


#4

I Rob,Thank you for your reply. Actually, the code i pasted would be
more like this:

<ul>
  <!-- The link you call "active" will show up as a darker tab -->
  <li> <% link_to :action => get_category, :category => 'pork' %> 
  • 3
  • <% link_to :action => get_category, :category => 'beef' %>
  • </ul>
    

    so @examples would be an array of my category names?

    Rob B. wrote:

    (resending without being signed, sorry if the original shows up)
    On Jun 1, 2007, at 10:55 AM, mixplate wrote:

      <li><a href="index.html">4</a></li>
      <li><a href="index.html">5</a></li>
    </ul>
    

    Assuming that the “index.html” would actually be based on the 1, 2,
    etc.:

      <% for example in @examples %>
    • <%= link_to_unless_current example, example_path(example) do |text| content_tag(:span, text, :class => 'active') end %>
    • <% end %>

    When @examples = [1,2,3,4,5]
    and example_path(3) => “/example/3”

    Gives:

    Is that what you’re looking for? The link_to_if, link_to_unless,
    link_to_unless_current helpers take a block that is passed the text
    of the link when the condition isn’t satisfied for making the link.

    -Rob

    Rob B. http://agileconsultingllc.com
    removed_email_address@domain.invalid


    #5

    Well, if you need to have

  • ... rather than
  • 1
  • -Rob

    Rob B. http://agileconsultingllc.com
    removed_email_address@domain.invalid


    Posted via http://www.ruby-forum.com/.

    Rob B. http://agileconsultingllc.com
    removed_email_address@domain.invalid
    +1 513-295-4739
    Skype: rob.biedenharn