0
我正在创建一个博客,我想通过单击index.html.erb中的“uploader”链接来显示包含特定用户的所有帖子的配置文件第9行)。我使用了名为Pages的控制器并在其中定义了配置文件,并将其链接到“上传者”并传递了该帖子的用户。ruby on rails - 找不到用户'id'=
我收到错误
终端显示用户ID作为零
Started GET "/" for 127.0.0.1 at 2017-03-27 02:08:49 +0530
Processing by PostsController#index as HTML
Post Load (0.5ms) SELECT "posts".* FROM "posts" ORDER BY created_at DESC
User Load (0.2ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? LIMIT 1 [["id", 4]]
User Load (0.2ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? LIMIT 1 [["id", 3]]
User Load (0.1ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? LIMIT 1 [["id", 2]]
Rendered posts/index.html.erb within layouts/application (10.8ms)
User Load (0.1ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? ORDER BY "users"."id" ASC LIMIT 1 [["id", 3]]
Completed 200 OK in 84ms (Views: 81.4ms | ActiveRecord: 1.1ms)
Started GET "/pages/profile.3" for 127.0.0.1 at 2017-03-27 01:49:02 +0530
Processing by PagesController#profile as
User Load (0.1ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? LIMIT 1 [["id", nil]]
Completed 404 Not Found in 1ms (ActiveRecord: 0.1ms)
ActiveRecord::RecordNotFound (Couldn't find User with 'id'=):
app/controllers/pages_controller.rb:3:in `profile'
什么时 “无法与 'ID'=查找用户”我做错了? 任何更好的方法来做到这一点?
也一样。更新我的routes.rb以获得'pages/profile /:id'。现在我收到错误“Missing:controller key on routes definition,please check your routes。(ArgumentError)” –
经过一些Google搜索后,我发现这个链接(http://guides.rubyonrails.org/routing.html),我想通了我的路线应该是“get”pages/profile /:id'=>'pages#profile',如:'profile'“,我可以使用<%= link_to”user profile“,profile_path(user )%> –