在我的Rails应用中,我有一个帖子部分允许用户提交内容。默认情况下,新帖子的URL约定将类似yoursite/posts/8
。我想知道是否有人知道是否有可能为用户创建一个自定义URL路由的方法,如制作一个新的帖子,然后有一个字符串“自定义URL”,因此它变得像'yoursite/posttopic'.
任何人都知道如何去做这件事?谢谢!Rails:邮件的自定义URL
邮政架构是这样的:
create_table "posts", force: :cascade do |t|
t.string "title"
t.text "body"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.integer "user_id"
t.string "image_file_name"
t.string "image_content_type"
t.integer "image_file_size"
t.datetime "image_updated_at"
end
您可能正在寻找[friendly_id(https://github.com/norman/friendly_id)宝石。 –