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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T06:52:16+00:00 2026-06-03T06:52:16+00:00

I am working on a simple rails 3 todo application and I am trying

  • 0

I am working on a simple rails 3 todo application and I am trying to filter the app by completed tasks and none completed task but whenever I try calling a scope I get the error message.

undefined method `completed' for #<Array:0x007fe8420d0e58>

task.rb

scope :completed , where(:completed => true)
scope :incomplete , where(:finished => false)

index.html.erb

<table>
  <tr>
    <th>Name</th>
    <th>Description</th>
    <th>Finished</th>
    <th>User</th>
  </tr>
  <% @tasks.each do |task| %>
  <tr>
    <td><%= task.name %><%= button_to "complete", complete_task_path(task.id)%></td>
    <td><%= task.description %></td>
    <td><%= task.finished %></td>
    <td><%= task.user_id %></td>
    <td><%= link_to 'Show', task %></td>
    <td><%= link_to 'Edit', edit_task_path(task) %></td>
    <td><%= link_to 'Destroy', task, confirm: 'Are you sure?', method: :delete %></td>
  </tr>
<% end %>
</table>

<%= content_tag :h2, "Stuff Ive done" %>
<table>
  <tr>
    <th>Name</th>
  </tr>
  <% @tasks.completed.each do |task| %>
  <tr>
    <td><%= task.name %></td>
  </tr>
<% end %>
</table>

task_controller.rb

def complete
 @task = Task.find(params[:task_id])
 @task.completed = true
 @task.save
 redirect_to task_path
end

routes.rb

match "tasks/:id/complete" => "task#complete", :as => :complete_task

Any reasons why rails is giving me this error?

  • 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-03T06:52:17+00:00Added an answer on June 3, 2026 at 6:52 am

    Just by looking at your view (index.html.erb), in one place, you are treating as a relation.

    <% @tasks.each do |task| %>
    

    Later in the code, you are trying to access it as a single object.

    <% @tasks.completed.each do |task| %>
    

    Since you are seeing the error on the second instance, you need to access ‘completed’ as in:

    <% @tasks.completed.each do |task| %>
      <% completed = task.completed %>
         <% completed.each do |com| %>
    

    Does this make sense?

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

Sidebar

Related Questions

I have a simple search working in my rails app, but it only searches
I m working on a simple Rails app called lists4me to create a minimalistic
Relatively new to rails, I'm working on a simple rails app for a few
I am working on a simple intranet application made with Rails 3.1. I have
I'm trying to get a simple bookmarklet working with Rails that creates a form
Trying to do a simple datatables implementation with my rails 3.2 app. I have
I've got a simple nested form working in my rails3 application. I'm trying to
I'm trying to get a What's new section working in my Rails app that
I am working on a very simple project to learn Rails better, coming from
I have the simple following code, which is working in a ruby (not rails)

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.