Ruby on rails 删除功能无法正常工作

Ruby on rails 删除功能无法正常工作,ruby-on-rails,ruby,Ruby On Rails,Ruby,我有一个删除函数的问题。我做了以下工作: 设置路线: resources :todos do member do delete :destroy_all end end 设置index.html.erb的链接 <%= link_to "Delete last seven days", destroy_all_todo_path(@todos), class: 'btn btn-success', method: :delete %> 并在我的控制器中定义了以下方

我有一个删除函数的问题。我做了以下工作:

设置路线:

resources :todos do
 member do 
  delete :destroy_all
 end
end
设置index.html.erb的链接

  <%= link_to "Delete last seven days", destroy_all_todo_path(@todos), class: 'btn btn-success', method: :delete %>

并在我的控制器中定义了以下方法:

def destroy_all
 @todo = Todo.where("created_at <= ?", Time.now - 7.days).destroy_all
if @todo.destroy
 flash[:notice] = "Your old todos are deled!"
else
 flash[:error] = "There was an error!"
end 
def destroy_all

@todo=todo。如@ptd在注释中所述,您正在删除对象,然后再次尝试删除它们。我会将您的代码更改为:

def destroy_all
 @todos = Todo.where("created_at <= ?", Time.now - 7.days)
if @todos.destroy_all
 flash[:notice] = "Your old todos are deled!"
else
 flash[:error] = "There was an error!"
end 
def destroy_all

@todos=Todo.where(“created_at如@ptd在注释中所述,您正在删除对象,然后再次尝试删除它们。我将您的代码更改为:

def destroy_all
 @todos = Todo.where("created_at <= ?", Time.now - 7.days)
if @todos.destroy_all
 flash[:notice] = "Your old todos are deled!"
else
 flash[:error] = "There was an error!"
end 
def destroy_all

@todos=Todo.where(“created_at如@ptd在注释中所述,您正在删除对象,然后再次尝试删除它们。我将您的代码更改为:

def destroy_all
 @todos = Todo.where("created_at <= ?", Time.now - 7.days)
if @todos.destroy_all
 flash[:notice] = "Your old todos are deled!"
else
 flash[:error] = "There was an error!"
end 
def destroy_all

@todos=Todo.where(“created_at如@ptd在注释中所述,您正在删除对象,然后再次尝试删除它们。我将您的代码更改为:

def destroy_all
 @todos = Todo.where("created_at <= ?", Time.now - 7.days)
if @todos.destroy_all
 flash[:notice] = "Your old todos are deled!"
else
 flash[:error] = "There was an error!"
end 
def destroy_all
@todos=Todo.where(“在这一行创建):

@todo = Todo.where("created_at <= ?", Time.now - 7.days).destroy_all
如果您仍然希望有备用方案,请添加一条rescue语句-destroy不会返回false,它将成功或引发异常。

此行:

@todo = Todo.where("created_at <= ?", Time.now - 7.days).destroy_all
如果您仍然希望有备用方案,请添加一条rescue语句-destroy不会返回false,它将成功或引发异常。

此行:

@todo = Todo.where("created_at <= ?", Time.now - 7.days).destroy_all
如果您仍然希望有备用方案,请添加一条rescue语句-destroy不会返回false,它将成功或引发异常。

此行:

@todo = Todo.where("created_at <= ?", Time.now - 7.days).destroy_all

如果您仍然希望有一个后备方案,请添加一个rescue语句-destroy不会返回false,它将成功或引发异常。

试着想象一下
如果@todo.destroy
在您已经运行
destroy\u all
之后会做什么。
@todo
中的值是什么?我认为
如果
声明我这里的nt没有意义。试着想象一下,
如果@todo.destroy
在你已经运行
destroy\u all
之后做了什么。
@todo
中的值是什么?我想这里的
如果
如果
没有意义。试着想象一下,
如果@todo.destroy
在你已经运行
destroy之后做了什么_所有
@todo
中的值是什么?我认为应该清楚这里的
if
语句没有意义。试着想象一下
如果@todo.destroy
在您已经运行
destroy\u all
之后会做什么。
@todo
中的值是什么?我认为应该清楚这里的
if
语句没有意义没道理。