Rails标记URL显示丑陋的“%23”

时间:2017-10-09 02:59:08

标签: ruby-on-rails url browser utf-8

我正在使用gem acts_as_taggable并希望使用hashtags#进行标记。但是,在网址中,它看起来像这样:http://localhost:3000/tags/%23tagname

我如何才能将显示为浏览器网址栏中的#tagname 而不是%23?

的routes.rb

  get 'tags/:tag', to: 'posts#index', as: :tag

new.html.erb

<%= f.label :tag_list, 'Tags (separated by commas)' %><br/>
<%= f.text_field :tag_list %>

schema.rb

  create_table "taggings", id: :serial, force: :cascade do |t|
    t.integer "tag_id"
    t.string "taggable_type"
    t.integer "taggable_id"
    t.string "tagger_type"
    t.integer "tagger_id"
    t.string "context", limit: 128
    t.datetime "created_at"
    t.index ["context"], name: "index_taggings_on_context"
    t.index ["tag_id", "taggable_id", "taggable_type", "context", "tagger_id", "tagger_type"], name: "taggings_idx", unique: true
    t.index ["tag_id"], name: "index_taggings_on_tag_id"
    t.index ["taggable_id", "taggable_type", "context"], name: "index_taggings_on_taggable_id_and_taggable_type_and_context"
    t.index ["taggable_id", "taggable_type", "tagger_id", "context"], name: "taggings_idy"
    t.index ["taggable_id"], name: "index_taggings_on_taggable_id"
    t.index ["taggable_type"], name: "index_taggings_on_taggable_type"
    t.index ["tagger_id", "tagger_type"], name: "index_taggings_on_tagger_id_and_tagger_type"
    t.index ["tagger_id"], name: "index_taggings_on_tagger_id"
  end

  create_table "tags", id: :serial, force: :cascade do |t|
    t.string "name"
    t.integer "taggings_count", default: 0
    t.index ["name"], name: "index_tags_on_name", unique: true
  end

1 个答案:

答案 0 :(得分:0)

这可能是gem尝试此版本或稳定版本的版本问题

gem 'acts-as-taggable-on', '~> 4.0'