我正在开发一个简单的 rails 3 todo 应用程序,我正在尝试通过已完成的任务和未完成的任务来过滤应用程序,但是每当我尝试调用范围时,我都会收到错误消息。
undefined method `completed' for #<Array:0x007fe8420d0e58>
任务.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
路线.rb
match "tasks/:id/complete" => "task#complete", :as => :complete_task
rails 给我这个错误的任何原因?