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

  • SEARCH
  • Home
  • 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 8888329
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T22:00:16+00:00 2026-06-14T22:00:16+00:00

I am using Rails 3, simple_form, and cocoon for a nested form for a

  • 0

I am using Rails 3, simple_form, and cocoon for a nested form for a Project that has_many TodoLists. I would like my simple_fields_for call to only include TodoLists that have not been soft-deleted, which is why I’d like to use my named scope “nondeleted”.

In my projects form I have:

<%= f.simple_fields_for :todo_lists, f.object.todo_lists.nondeleted do |todo_list_form| render "todo_list_fields", :f => todo_list_form end %>

This works fine on first load of my edit view (i.e. deleted TodoLists are not shown), but upon submitting the form with failed validation, any newly added TodoLists are lost.

If I remove the named scope, the newly added TodoLists are not lost upon failed validation, but then all TodoLists (including the deleted ones) are shown.

I’ve also tried the following:

<% @project.todo_lists.each do |todo_list| %>
    <% if !todo_list.deleted && !todo_list.name.blank? %>
     <%= f.simple_fields_for :todo_lists, todo_list do |todo_list_form| render "todo_list_fields", :f => todo_list_form end %>
    <% end %>
<% end %>

This solves both problems, but does not allow me the flexibility I need, such as the ability to keep the TodoLists in their proper order.

Is there a way to pass a collection to simple_fields_for (which, as far as I understand, has the same relevant behaviour as Rails’ fields_for) that will allow me to use a named scope and sorting without dropping newly added fields on failed validation?

  • 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-06-14T22:00:17+00:00Added an answer on June 14, 2026 at 10:00 pm

    I was able to resolve the issue by modifying my Project model’s has_many :todo_lists association as follows:

    has_many :todo_lists, :conditions => { :deleted => false }, :order => :name
    

    And in the view it’s simply:

    <%= f.simple_fields_for :todo_lists do |todo_list_form| render "todo_list_fields", :f => todo_list_form end %>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a nested form in a Rails 3.1 app, using Cocoon gem. In
I am using simple-form in rails and I would like to know if there
I have started using jQuery and rails. I have made a simple form that
I'm using Simple_form with Rails 3.2.1 All fine, except that I need to set
I'm using simple_form 1.5.2 + rails 3.1 gem in my project, but simple_form generates
I'm making my first Rails project and I'm using the simple_form gem (version 1.0)
I am working on a dynamically nested form using the cocoon gem. I have
I am using Mongoid on Rails 3 and trying to build a nested form.
I am using Ruby on Rails 3 and I would like to use RJS
I am using the rails 3 gem nested_forms and would like to change how

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.