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 3962566
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T03:06:43+00:00 2026-05-20T03:06:43+00:00

Rails likes giving all of my fields the same IDs when they are generated

  • 0

Rails likes giving all of my fields the same IDs when they are generated in a loop, and this causes trouble.

<% current_user.subscriptions.each do |s| %>
  <div class="subscription_listing">
    <%= link_to_function s.product.name, "toggle_delay(this)"%>
    in <%= s.calc_time_to_next_arrival %> days.
    <div class="modify_subscription">
        <%= form_for s, :url => change_subscription_path(s) do |f| %>
            <%= label_tag(:q, "Days to delay:") %>
            <%= text_field_tag(:query) %>
            <%= check_box_tag(:always) %>
            <%= label_tag(:always, "Apply delay to all future orders") %>
            <%= submit_tag("Change") %>
        <% end %>
        <%= link_to 'Destroy', s, :confirm => 'Are you sure?', :method => :delete %>
    </div>
  </div>
<% end %>

Produces

<div class="subscription_listing">
    <a href="#" onclick="toggle_delay(this); return false;">Pasta</a>
    in 57 days.
    <div class="modify_subscription">
        <form accept-charset="UTF-8" action="/subscriptions/7/change" class="edit_subscription" id="edit_subscription_7" method="post"><div style="margin:0;padding:0;display:inline"><input name="utf8" type="hidden" value="&#x2713;" /><input name="_method" type="hidden" value="put" /><input name="authenticity_token" type="hidden" value="s5LJffuzmbEMkSrez8b3KLVmDWN/PGmDryXhp25+qc4=" /></div>

            <label for="q">Days to delay:</label>
            <input id="query" name="query" type="text" />
            <input id="always" name="always" type="checkbox" value="1" />
            <label for="always">Apply delay to all future orders</label>
            <input name="commit" type="submit" value="Change" />
</form>     <a href="/subscriptions/7" data-confirm="Are you sure?" data-method="delete" rel="nofollow">Destroy</a>
    </div>

  </div>
  <div class="subscription_listing">
    <a href="#" onclick="toggle_delay(this); return false;">Gummy Bears</a>
    in 57 days.
    <div class="modify_subscription">
        <form accept-charset="UTF-8" action="/subscriptions/8/change" class="edit_subscription" id="edit_subscription_8" method="post"><div style="margin:0;padding:0;display:inline"><input name="utf8" type="hidden" value="&#x2713;" /><input name="_method" type="hidden" value="put" /><input name="authenticity_token" type="hidden" value="s5LJffuzmbEMkSrez8b3KLVmDWN/PGmDryXhp25+qc4=" /></div>
            <label for="q">Days to delay:</label>
            <input id="query" name="query" type="text" />

            <input id="always" name="always" type="checkbox" value="1" />
            <label for="always">Apply delay to all future orders</label>
            <input name="commit" type="submit" value="Change" />
</form>     <a href="/subscriptions/8" data-confirm="Are you sure?" data-method="delete" rel="nofollow">Destroy</a>
    </div>
  </div>

And that’s a problem because now no matter which “Apply delay to all future orders” I select it always very helpfully checks the first box for me. How can I override the ID without doing something ugly and un-rails-like?

  • 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-20T03:06:43+00:00Added an answer on May 20, 2026 at 3:06 am

    You should be able to override the id by passing it in as an option

    text_field_tag(:query, '', :id=>'unique id')
    check_box_tag(:always, '1', false, :id=>'unique_id')
    

    For instance

    <% current_user.subscriptions.each_with_index do |s,i| %>
      <div class="subscription_listing">
        <%= link_to_function s.product.name, "toggle_delay(this)"%>
        in <%= s.calc_time_to_next_arrival %> days.
        <div class="modify_subscription">
            <%= form_for s, :url => change_subscription_path(s) do |f| %>
                <%= label_tag("query_#{i}", "Days to delay:") %>
                <%= text_field_tag(:query, '', :id=>"query_#{i}") %>
                <%= check_box_tag(:always, '1', false, :id=>"always_#{i}") %>
                <%= label_tag("always_#{i}", "Apply delay to all future orders") %>
                <%= submit_tag("Change") %>
            <% end %>
            <%= link_to 'Destroy', s, :confirm => 'Are you sure?', :method => :delete %>
        </div>
      </div>
    <% end %>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Rails likes to get column attributes for each table you're using. On MySQL this
Are there any implementations of all the nifty Selenium on Rails methods like wait_for_visible
I'd like to have some rails apps over different servers sharing the same session.
I have a rails model that looks something like this: class Recipe < ActiveRecord::Base
In my Rails application I have a separate process (BackgroundRb) to delete all transactions
Greetings, all, I'm working on an application in Ruby on Rails where we need
This is a Rails 3 project. Am I abusing the use of cookies if
I am new to rails. Having a blast. The query API though is giving
I'm trying to install rails and its giving me a headache, I can't seem
I am attempting to cache a class variable like so: Rails.cache.write(@@page_types, @@page_types) This method

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.