Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6333703
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T18:30:59+00:00 2026-05-24T18:30:59+00:00

I got this very weird problem this evening when I was building something like

  • 0

I got this very weird problem this evening when I was building something like “filter-posts-by-multiple-tags” feature.

In the view template:

<%
tags = Tag.all
selected_tags ||= nil
%>

<ul>
    <% tags.each do |tag| %>
    <% logger.info("selected_tags size:"+ selected_tags.size.inspect) %>
    <li><%= link_or_span(tag, selected_tags) %></li>
    <% end %>
</ul>

In the TagsHelper:

module TagsHelper
  def link_or_span(tag, selected_tags)
    selected_tags.delete(tag)
    link_to tag.title, tag
  end
end

It outputs (in the log):

selected_tags size:2
selected_tags size:1
selected_tags size:0

What I expect:

selected_tags size:2
selected_tags size:2
selected_tags size:2

I think var “selected_tags” in the view template should be untouched each time in the loop since it’s in the different scope, isn’t it?

The ENV:

  • ruby 1.9.2p180 (2011-02-18 revision 30909) [x86_64-linux]
  • Rails 3.1.0.rc4
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T18:31:00+00:00Added an answer on May 24, 2026 at 6:31 pm
    selected_tags.delete(tag)
    

    replace to

    selected_tags.map {|t| tag.delete(t) }
    

    because I think your code will show all tag without selected_tag?it is right

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got very weird problem in my current project. The #head div looks like
I've got a very simple WPF UserControl that looks like this: namespace MyUserControl {
I've got a very simple WPF UserControl that looks like this: namespace WpfControlLibrary1 {
I've got a very weird and unexpected problem. empty() is returning TRUE on a
I got a VERY weird problem happening with ALL my DocumentCompleteEventHandlers. Say I have
This is a very strange problem. I've got a rails app in which I
This is very weird. I just got MonoDevelop (2.4.1) along with MonoTouch (3.2.2, evaluation
I got this very weird code: No debug, no work! I am almost crazy
I am having a very weird problem with building a SQL Server 2008 Database
I've got a weird maths/rounding problem in Javascript. The snippet below is a very

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.