0

我在我的 rails 项目中使用自动标记。我想从数据库中读取标签并显示给用户。我在控制器和 html 文件中使用以下代码,但不适用于自动标记化。(此代码适用于其他 select2,如 ajax。)

问题控制器.rb

respond_to :html, :json
def index
  @problem = Problem.order('status asc').all
  respond_with @problem
end

index.html.erb

<script type="text/javascript">
    $(document).ready(function(){

        $("#e20").select2({
            tags: {
                url: "/problems.json",
                dataType: "json",
                results: function(data, page) {
                    return {
                        results: $.map( data, function(problem, i) {
                            return { id: problem.id, text: problem.status }
                        } )
                    }
                }
            },
            tokenSeparators: [",", " "]
        });

    });

</script>

我的代码问题出在哪里?为什么这段代码无法读取数据库信息?

4

0 回答 0