我正在尝试保存我的Quotation模型的ID并将其存储在我的控制器上的cookie中。但是当我尝试读取cookie时,rails会显示异常重新输入的错误。
class BasicsController < ApplicationController
before_action :get_cookie
def quotations
if params[:quotation]
@quotation = Quotation.new( params.require(:quotation).permit(:author_name, :quote, :category) )
if @quotation.save
flash[:notice] = 'Quotation was successfully created.'
Quotation.new
end
else
@quotation = Quotation.new
end
if params[:sort_by] == "date"
@quotations = Quotation.order(:created_at)
else
@quotations = Quotation.order(:category)
end
end
def get_search
@quotations = Quotation.all
if params[:search]
@quotations = Quotation.search(params[:search])
else
@quotations = Quotation.all.order("created_at DESC")
end
end
def cookies
id = params[:id]
@removed_id = [1, 2, 3, 4]
cookies[:removed_id] = @removed_id
redirect_to basics_quotations_path
end
private
def get_cookie
cookies.delete :test
# @removed_ids = Array.new
puts @removed_ids.to_s
end
end