Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/67.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 如何将带有重定向的变量传递到?_Ruby On Rails_Ruby On Rails 3 - Fatal编程技术网

Ruby on rails 如何将带有重定向的变量传递到?

Ruby on rails 如何将带有重定向的变量传递到?,ruby-on-rails,ruby-on-rails-3,Ruby On Rails,Ruby On Rails 3,在我的controller destroy函数中,我想在删除项后重定向到index,并且我想在重定向时传递一个名为“checked”的变量: def destroy @Car = Car.find(params[:id]) checked = params[:checked] if @car.delete != nil end redirect_to cars_path #I would like to pass "checked" with car

在我的controller destroy函数中,我想在删除项后重定向到index,并且我想在重定向时传递一个名为“checked”的变量:

def destroy
    @Car = Car.find(params[:id])
    checked = params[:checked]

    if @car.delete != nil

    end

    redirect_to cars_path #I would like to pass "checked" with cars_path URL (call index)
end
如何使用cars\u path传递这个“checked”变量,以便在我的索引函数中获得它??(cars\u path调用索引函数)


如果您不介意url中显示参数,您可以:

redirect_to cars_path(:checked => params[:checked])
如果您真的介意,可以通过会话变量传递:

def destroy
  session[:tmp_checked] = params[:checked]
  redirect_to cars_path
end

def index
  checked = session[:tmp_checked]
  session[:tmp_checked] = nil # THIS IS IMPORTANT. Without this, you still get the last checked value when the user come to the index action directly.
end
看看这个:
def destroy
  session[:tmp_checked] = params[:checked]
  redirect_to cars_path
end

def index
  checked = session[:tmp_checked]
  session[:tmp_checked] = nil # THIS IS IMPORTANT. Without this, you still get the last checked value when the user come to the index action directly.
end