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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T13:29:11+00:00 2026-05-31T13:29:11+00:00

I’ve just started programming in rails 3 days ago, learned ruby by the same

  • 0

I’ve just started programming in rails 3 days ago, learned ruby by the same time, and I’m having a hard time since yesterday figuring how to with one form, delete/update some of my instances, I only use one model “Task”. Here’s the code:

<%= form_for @task do |f| %> 
    <ul>
    <% @tasks.each do |task| %>
        <li id="task"><%= f.check_box :done %> <%= f.label :name %> </li>
    <% end %>
    <button onclick="doUpdate()">Mark Selected as done </button>
    <%= button_to "Delete selected", :method => :delete  %>
    </ul>
<% end %>

Here’s the controller:

def delete
  @tasks = Task.find(:all, :conditions => ["task.done = ?", true])
  @tasks.each do |task|
    task.delete
  end

  @tasks = Task.all
end

My model have only 2 parameters. name:String and done:Boolean, I wan’t to delete all the selected checkboxes. But this don’t work for me

Thanks in advance.

  • 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-31T13:29:12+00:00Added an answer on May 31, 2026 at 1:29 pm

    The problem is, you are doing it wrong(and I’ll tell you why). I could paste the code that would make it work but I’d rather explain, as you are probably doing it to learn.

    Task.find(:all, :conditions => ["done = ?", true]) will return EVERYTHING in your database where done = true. You will be erasing everything that is marked as done in the DATABASE, not what were marked on the form. Task is your model, you can access the database by using find, where and other methods from activerecord(if activerecord doesn’t sound natural to you, activerecord lets you get stuff from the database without the need of writing SQL queries).

    What you really need to do in your controller is:
    – You have to get what was sent from the form (check the documentation/web resources for the usage of param[] ).
    – For every checkbox marked true, you erase a record. (you got the each part right, this is good!)

    I don’t think your view is right, I advise you to first be sure that the data that you receive is right(the params[]), then proceed to try to erase the record, or do whatever you want to do with it.

    To “test” if your variables and code that is inside your controllers and models, use print @variable or something else(check rails docs how to debug).

    I advise you use destroy instead of delete as other fellow stackoverflowers have said. Read the docs of destroy and delete.

    Keep going 🙂

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
We're building an app, our first using Rails 3, and we're having to build
I have just tried to save a simple *.rtf file with some websites and
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm having trouble keeping the paragraph square between the quote marks. In firefox the
For some reason, after submitting a string like this Jack’s Spindle from a text
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
I would like to count the length of a string with PHP. The string

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.