gpt4 book ai didi

ruby-on-rails - 如何让 friendly_id gem 与 Rails 5.0.0.rc1 一起工作?

转载 作者:行者123 更新时间:2023-12-05 09:20:21 30 4
gpt4 key购买 nike

我在我的 Rails 应用程序中使用 friendly_id。我在 gemfile 中有以下内容。

gem 'friendly_id', '~> 5.1'

每当我访问用户个人资料时,我都会收到 404 错误。

suai@rails-tutorial:~/workspace/iya (master) $ rails server -b $IP -p $PORT
=> Booting WEBrick
=> Rails 5.0.0.rc1 application starting in development on http://0.0.0.0:8080
=> Run `rails server -h` for more startup options
[2016-06-07 05:54:21] INFO WEBrick 1.3.1
[2016-06-07 05:54:21] INFO ruby 2.3.1 (2016-04-26) [x86_64-linux]
[2016-06-07 05:54:21] INFO WEBrick::HTTPServer#start: pid=74846 port=8080
Started GET "/users/testtest" for 98.5.56.144 at 2016-06-07 05:54:25 +0000
Cannot render console from 98.5.56.144! Allowed networks: 127.0.0.1, ::1, 127.0.0.0/127.255.255.255
ActiveRecord::SchemaMigration Load (0.2ms) SELECT "schema_migrations".* FROM "schema_migrations"
Processing by UsersController#show as HTML
Parameters: {"id"=>"testtest"}
User Load (0.4ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? LIMIT ? [["id", 0], ["LIMIT", 1]]
Rendering public/404.html within layouts/application
Rendered public/404.html within layouts/application (8.5ms)
Rendered layouts/_shim.html.erb (0.8ms)
Rendered layouts/_header.html.erb (2.3ms)
Rendered layouts/_footer.html.erb (2.2ms)
Completed 404 Not Found in 924ms (Views: 848.5ms | ActiveRecord: 2.1ms)

用户 Controller ,显示方法

  def show
@user = User.find(params[:id])
@microposts = @user.microposts.paginate(page: params[:page])
respond_to do |format|
format.html
format.js
end
end

用户.rb

  extend FriendlyId
friendly_id :name, use: [:slugged, :finders]

我认为 friendly_id 不起作用。
知道如何解决这个问题吗?谢谢

最佳答案

当你想使用...

extend FriendlyId
friendly_id :name, use: [:slugged, :finders]

...你需要安装主分支(friendly_id 5.2.0.beta.1)

gem 'friendly_id', github: 'norman/friendly_id'

如果这样做,则不必更改 Controller (Model.friendly.find)

关于ruby-on-rails - 如何让 friendly_id gem 与 Rails 5.0.0.rc1 一起工作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37671409/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com