Multiparameter / ActiveSupport :: HashWithIndifferentAccess Rails 3

时间:2014-02-13 18:12:24

标签: ruby-on-rails ruby search

我有一个允许用户搜索的Ruby应用程序。我正在构建一个数据存储表,用于保存站点上发生的每个搜索。在创作中,我传递了一些东西:

ID of returned object controller action Search term ip address of user additional filters

在这5个项目中,4个是单数并且工作正常,但是,additional filters是多个保存为奇怪的转义字符串。如果我发送只是保存过滤器,它看起来像这样:

"---\n- !ruby/hash:ActiveSupport::HashWithIndifferentAccess\n  type: city\n  value: San Francisco\n- !ruby/hash:ActiveSupport::HashWithIndifferentAccess\n  type: sport\n  value: Basketball\n- !ruby/hash:ActiveSupport::HashWithIndifferentAccess\n  type: sport\n  value: Football\n" 

这是这些过滤器的输出: [{"type"=>"city", "value"=>"San Francisco"}, {"type"=>"sport", "value"=>"Basketball"}, {"type"=>"sport", "value"=>"Football"}]

我尝试了很多方法,但我不能按照我想要的方式清理它。如何避免HashWithIndifferentAccess或调整结果。

SCHEMA:

create_table "search_counts", :force => true do |t|
    t.integer  "search_countable_id"
    t.string   "search_countable_type"
    t.integer  "search_returns"
    t.datetime "created_at",            :null => false
    t.datetime "updated_at",            :null => false
  end

 create_table "search_count_details", :force => true do |t|
    t.integer  "search_count_id"
    t.string   "ip_address",      :limit => 15
    t.datetime "created_at",                    :null => false
    t.datetime "updated_at",                    :null => false
    t.string   "action"
    t.string   "query"
    t.text     "filters"
 end

0 个答案:

没有答案