Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/60.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 - Fatal编程技术网

Ruby on rails 下拉菜单中的链接不起作用

Ruby on rails 下拉菜单中的链接不起作用,ruby-on-rails,Ruby On Rails,我试图在ROR视图页面中显示我数据库中的类别下拉列表,我想提供一个链接,以删除下拉列表中选定的类别。我已经写了以下代码,但它不工作,请帮助我 我的代码是: class CatvaluesController < ApplicationController def index @catvalue = Catvalue.new @catvalues = Catvalue.all @categories = Category.all

我试图在ROR视图页面中显示我数据库中的类别下拉列表,我想提供一个链接,以删除下拉列表中选定的类别。我已经写了以下代码,但它不工作,请帮助我

我的代码是:

class CatvaluesController < ApplicationController
    def index
        @catvalue = Catvalue.new
        @catvalues = Catvalue.all
        @categories = Category.all
    end

    def destroy
        @catvalue_del = Catvalue.find(params[:id])
        @catvalue_del.destroy
        redirect_to catvalues_path
    end
end
index.html.erb

 <%= collection_select(:catvalue, :id, @catvalues, :id, :v_name, {}, class: 'drop-down')%>
 <%= link_to 'Destroy', {:catvalue => :id},method: :delete, data: { confirm: 'Are you sure?' } %>

:id},方法::删除,数据:{确认:'确定吗?'}%>
还有我的

控制器为:

class CatvaluesController < ApplicationController
    def index
        @catvalue = Catvalue.new
        @catvalues = Catvalue.all
        @categories = Category.all
    end

    def destroy
        @catvalue_del = Catvalue.find(params[:id])
        @catvalue_del.destroy
        redirect_to catvalues_path
    end
end
class CatvaluesController

但是它不起作用

你应该把它放在表单中,然后提交表单。使用表单我有很多下拉菜单,我需要在表单中使用哪个控制器,“@catvalue=catvalue.new”或“@catvalue=catvalue.all”@misha你能给我表单标题吗,我的控制器已经在那里了。非常感谢。