🎄teratailクリスマスプレゼントキャンペーン2024🎄』開催中!

\teratail特別グッズやAmazonギフトカード最大2,000円分が当たる!/

詳細はこちら
Ruby on Rails 5

Ruby on Rails 5は、オープンソースのWebアプリケーションフレームワークです。「同じことを繰り返さない」というRailsの基本理念のもと、他のフレームワークより少ないコードで簡単に開発できるよう設計されています。

Q&A

解決済

1回答

700閲覧

rails indexにある任意のデータをクリックしたら、そのデータを持ってきて、任意のユーザーのページでクリックした投稿をまとめて一覧で表示したい

tori315

総合スコア21

Ruby on Rails 5

Ruby on Rails 5は、オープンソースのWebアプリケーションフレームワークです。「同じことを繰り返さない」というRailsの基本理念のもと、他のフレームワークより少ないコードで簡単に開発できるよう設計されています。

0グッド

0クリップ

投稿2019/12/16 05:56

詰まっているところ
クリックしたデータを保持するdb(user_idとpost_idカラムがある)のpost_idが正常に入らない。
id|user_id|post_id|created_at|updated_at
45|26|2|2019-12-16 05:32:28.576273|2019-12-16 05:32:28.576273

post_idはクリックしたidではなく、いつも「2」になってしまう。
たくさん載せて申し訳ないのですが、どうぞよろしくお願い致します。

index.html.erb

1<body id="posts-index"> 2 <div class="container-fluid"> 3 4 <div class="posts-page row"> 5 <%= form_tag("/accepted/#{@current_user.id}/accepted",method: :post,data:{confirm:"このクエストを受けますか?"}) do %> 6 <% @posts.each do |post| %> 7 <div class="posts-left col-md-6"> 8 <div class="posts-content row"> 9 <div class="posts-content-left col-md-6"> 10 <p>受付No</p> 11 <input type="text" name="post_id" required readonly value="<%= post.id %>" class="content-waku"> 12 13 <p>受付日時</p> 14 <h6 class="content-waku"><%= post.created_at %></h6> 15 <p>タイトル</p> 16 <h6 class="content-waku"><%= post.title %></h6> 17 <p>ジャンル</p> 18 <h6 class="content-waku"><%= post.category %></h6> 19 <p>報酬</p> 20 <h6 class="content-waku"><%= post.money %>円</h6> 21 <p>仕事日</p> 22 <h6 class="content-waku"><%= post.jobDate %></h6> 23 <p>性別(求める性別)</p> 24 <h6 class="content-waku"><%= post.radio %></h6> 25 <p>クエスト場所</p> 26 <h6 class="content-waku"><%= post.where %></h6> 27 <p>キャンセル締切日</p> 28 <h6 class="content-waku"><%= post.cancel %></h6> 29 <% if post.img != nil %> 30 <p>画像</p> 31 <img src="<%= "/post_images/#{post.id}.jpg" %>" class="content-waku" > 32 <%else%> 33 <p>画像</p> 34 <img src="<%= "/post_images/brawn.jpg" %>" class="content-waku" > 35 <%end%>     36 </div> 37 <div class="posts-content-right col-md-6"> 38 <p>依頼者ID</p> 39 <h6 class="content-waku"><%= post.user_id %></h6> 40 41 <p>依頼者</p> 42 <h6 class="content-waku"><%= post.postedname %></h6>  43 <p>クエストの内容</p> 44 <h6 class="content-waku"><%= post.content %></h6> 45 <button id="btn1" type="submit" class="btn btn-success btn-lg ">クエストを受ける</button> 46 47 </div> 48 </div> 49 </div> 50 <% end %> 51 <% end %> 52 53 </div> 54 </div> 55 <%= yield %> 56

AcceptController

1class AcceptController < ApplicationController 2before_action:authenticate_user,{only:[:acceptednew,:accepted]} 3before_action:ensure_current_user,{only:[:acceptednew,:accepted]} 4 5 6def acceptednew 7 @accept = Accept.new( 8 user_id: @current_user.id, 9 post_id: params[:post_id] 10 ) 11 @accept.save 12 redirect_to("/users/#{@current_user.id}") 13end 14 15 16def accepted 17 @user = User.find_by(id: params[:id]) 18 @accepteds = Accept.where(user_id: @user.id) 19end 20 21 22 23end 24

PostsController

1class PostsController < ApplicationController 2 before_action:set_post,only: [:show,:edit,:update,:destroy] 3 before_action:authenticate_user,{only:[:index,:show,:edit,:update,:destroy,:questpage]} 4 5 def kensaku 6 end 7 8 9 def index 10 if params[:q] 11 @search = Post.ransack(params[:q]) 12 @posts = @search.result(distinct: true) 13 14 else 15 @posts = Post.all.order(created_at: :desc) 16 end 17 end 18 19 def new 20 @post = Post.new 21 end 22 23 def create 24 @post = Post.new(post_params) 25 @post.user_id = @current_user.id 26 @post.save 27 if params[:img] 28 @post.img = "#{@post.id}.jpg" 29 image = params[:img] 30 File.binwrite("public/post_images/#{@post.id}.jpg",image.read) 31 else 32 @post.img = nil 33 end 34 if @post.save 35 flash[:notice] = "登録に成功しました" 36 redirect_to("/posts/index") 37 else 38 render("/posts/new") 39 end 40 end 41 42 def post_params 43 params.permit(:title, :category, :money, :jobDate, :radio, :where, :cancel, :img, :postedname, :content,:user_id) 44 end 45 46 def show 47 @post = Post.find_by(id:params[:id]) 48 end 49 50 def edit 51 @post = Post.find_by(id:params[:id]) 52 end 53 54 55 def update 56 @post.update(post_params) 57 if params[:img] 58 @post.img = "#{@post.id}.jpg" 59 image = params[:img] 60 File.binwrite("public/post_images/#{@post.id}.jpg",image.read) 61 else 62 @post.img = nil 63 end 64 if @post.save 65 flash[:notice] = "編集に成功しました" 66 redirect_to("/posts/index") 67 else 68 render("/posts/edit") 69 end 70 end 71 72 73 def destroy 74 @post.destroy 75 flash[:notice] = "削除に成功しました" 76 redirect_to("/users/#{@current_user.id}") 77 end 78 79 def set_post 80 @post = Post.find_by(id:params[:id]) 81 end 82 83 def questpage 84 end 85 86 87 88 89end 90 91コード

routes

1get "posts/index" => "posts#index" 2 get "posts/new" => "posts#new" 3 post "posts/create" => "posts#create" 4 get "posts/questpage" => "posts#questpage" 5 get "posts/kensaku" => "posts#kensaku" 6 get "posts/:id" => "posts#show" 7 get "posts/:id/edit" => "posts#edit" 8 post "posts/:id/update"=> "posts#update" 9 post "posts/:id/destroy" => "posts#destroy" 10 11get "login" => "users#login" 12 post "users/login" => "users#loginafter" 13 get "signup" => "users#new" 14 post "users/create" => "users#create" 15 get "users/index" => "users#index" 16 get "users/:id" => "users#show" 17 post "users/:id" => "users#destroy" 18 post "logout" => "users#logout" 19 get "users/:id/edit" => "users#edit" 20 post "users/:id/update" => "users#update" 21 get "users/:id/posted"=> "users#posted" 22 23 post "accepted/:id/accepted"=>"accept#acceptednew" 24 get "accepted/:id/accepted"=>"accept#accepted" 25end

Schema.rb

1create_table "accepts", force: :cascade do |t| 2 t.integer "user_id" 3 t.integer "post_id" 4 t.datetime "created_at", null: false 5 t.datetime "updated_at", null: false 6 end 7 8 create_table "posts", force: :cascade do |t| 9 t.string "title" 10 t.string "category" 11 t.string "where" 12 t.date "cancel" 13 t.text "content" 14 t.datetime "created_at", null: false 15 t.datetime "updated_at", null: false 16 t.string "radio" 17 t.string "jobDate" 18 t.string "img" 19 t.string "money" 20 t.string "postedname" 21 t.string "postedpic" 22 t.integer "user_id" 23 end 24 25 create_table "users", force: :cascade do |t| 26 t.string "user_name" 27 t.string "password_digest" 28 t.string "email" 29 t.datetime "created_at", null: false 30 t.datetime "updated_at", null: false 31 t.string "imagename" 32 end

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

退会済みユーザー

退会済みユーザー

2019/12/16 07:18

試して欲しいことがあるのですが、 <p>受付No</p> <input type="text" name="post_id" required readonly value="<%= post.id %>" class="content-waku"> のvalueに<%= post.id %>ではなく適当な数値を入れた場合は、DBに保存されるデータは何になるでしょうか?
tori315

2019/12/16 08:01

適当に数字を入れると、その数字がでます。
退会済みユーザー

退会済みユーザー

2019/12/16 08:22

<input type="text" name="post_id" required readonly value="<%= post.id %>" class="content-waku"> ↓ <input type="text" name="post_id" required readonly value="#{post.id}" class="content-waku"> valueの部分を上記のように変更してください。
tori315

2019/12/16 08:36

そのようにしたら、 そのまま{post.id}が表示されてしまいました。
退会済みユーザー

退会済みユーザー

2019/12/16 09:09 編集

すみません。上のは一旦忘れてください。 前にも話が出ていましたが、ログがどうなっているのか気になります。 [$rails s]をしているところ(macを使っているならターミナル)に出てくる文字列を確認してみてください。 送信ボタンをおした後、以下のような文字列が出力されていると思います。(Railsドキュメントより引用) ``` Started POST "/articles" for 127.0.0.1 at 2017-08-20 20:53:10 +0900 Processing by ArticlesController#create as HTML Parameters: {"utf8"=>"✓", "authenticity_token"=>"xhuIbSBFytHCE1agHgvrlKnSVIOGD6jltW2tO+P6a/ACjQ3igjpV4OdbsZjIhC98QizWH9YdKokrqxBCJrtoqQ==", "article"=>{"title"=>"Debugging Rails", "body"=>"I'm learning how to print in logs!!!", "published"=>"0"}, "commit"=>"Create Article"} New article: {"id"=>nil, "title"=>"Debugging Rails", "body"=>"I'm learning how to print in logs!!!", "published"=>false, "created_at"=>nil, "updated_at"=>nil} (0.1ms) BEGIN SQL (0.4ms) INSERT INTO "articles" ("title", "body", "published", "created_at", "updated_at") VALUES ($1, $2, $3, $4, $5) RETURNING "id" [["title", "Debugging Rails"], ["body", "I'm learning how to print in logs!!!"], ["published", "f"], ["created_at", "2017-08-20 11:53:10.010435"], ["updated_at", "2017-08-20 11:53:10.010435"]] (0.3ms) COMMIT Redirected to http://localhost:3000/articles/1 Completed 302 Found in 4ms (ActiveRecord: 0.8ms) ``` 3行目の「Parameters...」以降にコントローラに渡っているパラメータが書いてあるので、どうなっているか教えていただきたいです。
退会済みユーザー

退会済みユーザー

2019/12/16 09:11

下でindexを開いた時のログを載せているように、送信ボタンを押した時のログも載せてもらえますか?
tori315

2019/12/16 09:23

logはこんな感じになっています。 Started POST "/accepted/26/accepted" for ::1 at 2019-12-16 18:22:11 +0900 Processing by AcceptController#acceptednew as HTML Parameters: {"utf8"=>"✓", "authenticity_token"=>"4HcoYAC4TXuI98wKcZHXhdlvcKEIBTwde96NLW2yIyOV4FeQ3Job44vadhydwE45oMG6paM/KBkHBoI33PnWmg==", "post_id"=>"2", "id"=>"26"} User Load (1.2ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? LIMIT ? [["id", 26], ["LIMIT", 1]] ↳ app/controllers/application_controller.rb:6 Post Load (10.6ms) SELECT "posts".* FROM "posts" WHERE "posts"."id" = ? LIMIT ? [["id", 2], ["LIMIT", 1]] ↳ app/controllers/accept_controller.rb:8 (0.1ms) begin transaction ↳ app/controllers/accept_controller.rb:13 Accept Create (13.3ms) INSERT INTO "accepts" ("user_id", "post_id", "created_at", "updated_at") VALUES (?, ?, ?, ?) [["user_id", 26], ["post_id", 2], ["created_at", "2019-12-16 18:22:12.653896"], ["updated_at", "2019-12-16 18:22:12.653896"]] ↳ app/controllers/accept_controller.rb:13 (124.3ms) commit transaction ↳ app/controllers/accept_controller.rb:13 Redirected to http://localhost:3000/users/26 Completed 302 Found in 991ms (ActiveRecord: 151.5ms) Started GET "/users/26" for ::1 at 2019-12-16 18:22:13 +0900 Processing by UsersController#show as HTML Parameters: {"id"=>"26"} User Load (0.4ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? LIMIT ? [["id", 26], ["LIMIT", 1]] ↳ app/controllers/application_controller.rb:6 User Load (0.5ms) SELECT "users".* FROM "users" WHERE "users"."id" IS NULL LIMIT ? [["LIMIT", 1]] ↳ app/controllers/users_controller.rb:30 (0.5ms) SELECT COUNT(*) FROM "accepts" WHERE "accepts"."user_id" = ? [["user_id", 26]] ↳ app/controllers/users_controller.rb:31 (1.2ms) SELECT COUNT(*) FROM "posts" WHERE "posts"."user_id" = ? [["user_id", 26]] ↳ app/controllers/users_controller.rb:32 Rendering users/show.html.erb within layouts/application Rendered users/show.html.erb within layouts/application (7.8ms) Completed 200 OK in 466ms (Views: 280.4ms | ActiveRecord: 2.6ms) Started GET "/users/users.scss" for ::1 at 2019-12-16 18:22:14 +0900 Started GET "/users/home-mobile.scss" for ::1 at 2019-12-16 18:22:14 +0900 Started GET "/users/home.scss" for ::1 at 2019-12-16 18:22:14 +0900 Processing by UsersController#show as Parameters: {"id"=>"users"} User Load (0.4ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? LIMIT ? [["id", 26], ["LIMIT", 1]] Processing by UsersController#show as ↳ app/controllers/application_controller.rb:6 Parameters: {"id"=>"home-mobile"} User Load (0.4ms) SELECT "users".* FROM "users" WHERE "users"."id" IS NULL LIMIT ? [["LIMIT", 1]] User Load (0.4ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? LIMIT ? [["id", 26], ["LIMIT", 1]] ↳ app/controllers/users_controller.rb:30 ↳ app/controllers/application_controller.rb:6 User Load (1.1ms) SELECT "users".* FROM "users" WHERE "users"."id" IS NULL LIMIT ? [["LIMIT", 1]] ↳ app/controllers/users_controller.rb:30 (0.4ms) SELECT COUNT(*) FROM "accepts" WHERE "accepts"."user_id" = ? [["user_id", 26]] (0.5ms) SELECT COUNT(*) FROM "accepts" WHERE "accepts"."user_id" = ? [["user_id", 26]] ↳ app/controllers/users_controller.rb:31 ↳ app/controllers/users_controller.rb:31 (1.1ms) SELECT COUNT(*) FROM "posts" WHERE "posts"."user_id" = ? [["user_id", 26]] ↳ app/controllers/users_controller.rb:32 (1.1ms) SELECT COUNT(*) FROM "posts" WHERE "posts"."user_id" = ? [["user_id", 26]] Processing by UsersController#show as ↳ app/controllers/users_controller.rb:32 Parameters: {"id"=>"home"} Rendering users/show.html.erb within layouts/application User Load (0.6ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? LIMIT ? [["id", 26], ["LIMIT", 1]] Rendered users/show.html.erb within layouts/application (3.7ms) ↳ app/controllers/application_controller.rb:6 Rendering users/show.html.erb within layouts/application User Load (1.1ms) SELECT "users".* FROM "users" WHERE "users"."id" IS NULL LIMIT ? [["LIMIT", 1]] ↳ app/controllers/users_controller.rb:30 Rendered users/show.html.erb within layouts/application (0.7ms) (0.5ms) SELECT COUNT(*) FROM "accepts" WHERE "accepts"."user_id" = ? [["user_id", 26]] ↳ app/controllers/users_controller.rb:31 (0.5ms) SELECT COUNT(*) FROM "posts" WHERE "posts"."user_id" = ? [["user_id", 26]] ↳ app/controllers/users_controller.rb:32 Rendering users/show.html.erb within layouts/application Rendered users/show.html.erb within layouts/application (0.3ms) Completed 200 OK in 1215ms (Views: 736.9ms | ActiveRecord: 3.0ms) Completed 200 OK in 1655ms (Views: 712.8ms | ActiveRecord: 2.4ms) Started GET "/users/home-mobile.scss" for ::1 at 2019-12-16 18:22:16 +0900 Completed 200 OK in 954ms (Views: 448.0ms | ActiveRecord: 2.7ms) Processing by UsersController#show as Parameters: {"id"=>"home-mobile"} User Load (0.4ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? LIMIT ? [["id", 26], ["LIMIT", 1]] ↳ app/controllers/application_controller.rb:6 User Load (0.3ms) SELECT "users".* FROM "users" WHERE "users"."id" IS NULL LIMIT ? [["LIMIT", 1]] ↳ app/controllers/users_controller.rb:30 (0.5ms) SELECT COUNT(*) FROM "accepts" WHERE "accepts"."user_id" = ? [["user_id", 26]] ↳ app/controllers/users_controller.rb:31 (1.0ms) SELECT COUNT(*) FROM "posts" WHERE "posts"."user_id" = ? [["user_id", 26]] ↳ app/controllers/users_controller.rb:32 Rendering users/show.html.erb within layouts/application Rendered users/show.html.erb within layouts/application (1.5ms) Completed 200 OK in 363ms (Views: 168.4ms | ActiveRecord: 2.1ms) Started GET "/users/home.scss" for ::1 at 2019-12-16 18:22:17 +0900 Processing by UsersController#show as Parameters: {"id"=>"home"} User Load (0.7ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? LIMIT ? [["id", 26], ["LIMIT", 1]] ↳ app/controllers/application_controller.rb:6 User Load (0.3ms) SELECT "users".* FROM "users" WHERE "users"."id" IS NULL LIMIT ? [["LIMIT", 1]] ↳ app/controllers/users_controller.rb:30 (0.4ms) SELECT COUNT(*) FROM "accepts" WHERE "accepts"."user_id" = ? [["user_id", 26]] ↳ app/controllers/users_controller.rb:31 (0.4ms) SELECT COUNT(*) FROM "posts" WHERE "posts"."user_id" = ? [["user_id", 26]] ↳ app/controllers/users_controller.rb:32 Rendering users/show.html.erb within layouts/application Rendered users/show.html.erb within layouts/application (2.4ms) Completed 200 OK in 288ms (Views: 186.0ms | ActiveRecord: 1.8ms)
tori315

2019/12/16 10:38

ありがとうございました。 <% @posts.each do |post| %> <%= form_tag("/accepted/#{@current_user.id}/accepted",method: :post,data:{confirm:"このクエストを受けますか?"}) do %> ループの中にform_tagを書いたら出来ました。 いろいろ考えてくださってありがとうございます。
退会済みユーザー

退会済みユーザー

2019/12/16 12:09

確かにその通りですね…! 解決してよかったです!
guest

回答1

0

ベストアンサー

read_only ですとデータが渡されないかもしれない。
(disable にするとそうなります。read_onlyは未確認ですが)

それを確認するために log/developmen.log の該当部分を見たいです。
それを省くなら

<input type="text" name="post_id" required readonly value="<%= post.id %>" class="content-waku"> の直後に
<input type="hidden" name="post_id" value="<%= post.id %>" >
をつけてみてください

投稿2019/12/16 06:45

winterboum

総合スコア23567

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

tori315

2019/12/16 08:08

<input type="hidden" name="post_id" value="<%= post.id %>" >を入れてみましたが、変わらずでした。 log/developmen.logは他にもエラーがあるのか、すごい行になっていて、それがどこかもう分からない状態です。。
winterboum

2019/12/16 08:12

logですが、ブラウザーからのアクセスごとにStarted で始まっています。 一番後ろからStartedを見て行って、エラーの出た時刻を参考に探してください。
winterboum

2019/12/16 08:13

もしくは、 サーバを止めて log/development.logを削除(か名前変更)して サーバを起動 すると0から書き出してくれます
tori315

2019/12/16 09:02

新しく始めて、そのindexをクリックした辺りのlogです。 Started GET "/accepted/26/accepted" for ::1 at 2019-12-16 17:54:19 +0900 Processing by AcceptController#accepted as HTML Parameters: {"id"=>"26"} User Load (0.3ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? LIMIT ? [["id", 26], ["LIMIT", 1]] ↳ app/controllers/application_controller.rb:6 User Load (0.3ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? LIMIT ? [["id", 26], ["LIMIT", 1]] ↳ app/controllers/accept_controller.rb:19 Rendering accept/accepted.html.erb within layouts/application Accept Load (0.5ms) SELECT "accepts".* FROM "accepts" WHERE "accepts"."user_id" = ? [["user_id", 26]] ↳ app/views/accept/accepted.html.erb:39 Post Load (0.5ms) SELECT "posts".* FROM "posts" WHERE "posts"."id" = ? LIMIT ? [["id", 2], ["LIMIT", 1]] ↳ app/views/accept/accepted.html.erb:40 CACHE Post Load (0.0ms) SELECT "posts".* FROM "posts" WHERE "posts"."id" = ? LIMIT ? [["id", 2], ["LIMIT", 1]] ↳ app/views/accept/accepted.html.erb:40 Rendered accept/accepted.html.erb within layouts/application (11.2ms) Completed 200 OK in 139ms (Views: 119.2ms | ActiveRecord: 1.7ms) Started GET "/accepted/26/home.scss" for ::1 at 2019-12-16 17:54:20 +0900 Started GET "/accepted/26/home-mobile.scss" for ::1 at 2019-12-16 17:54:20 +0900 Started GET "/accepted/26/users.scss" for ::1 at 2019-12-16 17:54:20 +0900 ActionController::RoutingError (No route matches [GET] "/accepted/26/home-mobile.scss"): actionpack (5.2.4) lib/action_dispatch/middleware/debug_exceptions.rb:65:in `call' web-console (3.7.0) lib/web_console/middleware.rb:135:in `call_app' web-console (3.7.0) lib/web_console/middleware.rb:30:in `block in call' web-console (3.7.0) lib/web_console/middleware.rb:20:in `catch' web-console (3.7.0) lib/web_console/middleware.rb:20:in `call' actionpack (5.2.4) lib/action_dispatch/middleware/show_exceptions.rb:33:in `call' railties (5.2.4) lib/rails/rack/logger.rb:38:in `call_app' railties (5.2.4) lib/rails/rack/logger.rb:26:in `block in call' activesupport (5.2.4) lib/active_support/tagged_logging.rb:71:in `block in tagged' activesupport (5.2.4) lib/active_support/tagged_logging.rb:28:in `tagged' activesupport (5.2.4) lib/active_support/tagged_logging.rb:71:in `tagged' railties (5.2.4) lib/rails/rack/logger.rb:26:in `call' sprockets-rails (3.2.1) lib/sprockets/rails/quiet_assets.rb:13:in `call' actionpack (5.2.4) lib/action_dispatch/middleware/remote_ip.rb:81:in `call' actionpack (5.2.4) lib/action_dispatch/middleware/request_id.rb:27:in `call' rack (2.0.7) lib/rack/method_override.rb:22:in `call' rack (2.0.7) lib/rack/runtime.rb:22:in `call' activesupport (5.2.4) lib/active_support/cache/strategy/local_cache_middleware.rb:29:in `call' actionpack (5.2.4) lib/action_dispatch/middleware/executor.rb:14:in `call' actionpack (5.2.4) lib/action_dispatch/middleware/static.rb:127:in `call' rack (2.0.7) lib/rack/sendfile.rb:111:in `call' railties (5.2.4) lib/rails/engine.rb:524:in `call' puma (3.12.1) lib/puma/configuration.rb:227:in `call' puma (3.12.1) lib/puma/server.rb:660:in `handle_request' puma (3.12.1) lib/puma/server.rb:474:in `process_client' puma (3.12.1) lib/puma/server.rb:334:in `block in run' puma (3.12.1) lib/puma/thread_pool.rb:135:in `block in spawn_thread' ActionController::RoutingError (No route matches [GET] "/accepted/26/home.scss"): actionpack (5.2.4) lib/action_dispatch/middleware/debug_exceptions.rb:65:in `call' web-console (3.7.0) lib/web_console/middleware.rb:135:in `call_app' web-console (3.7.0) lib/web_console/middleware.rb:30:in `block in call' web-console (3.7.0) lib/web_console/middleware.rb:20:in `catch' web-console (3.7.0) lib/web_console/middleware.rb:20:in `call' actionpack (5.2.4) lib/action_dispatch/middleware/show_exceptions.rb:33:in `call' railties (5.2.4) lib/rails/rack/logger.rb:38:in `call_app' railties (5.2.4) lib/rails/rack/logger.rb:26:in `block in call' activesupport (5.2.4) lib/active_support/tagged_logging.rb:71:in `block in tagged' activesupport (5.2.4) lib/active_support/tagged_logging.rb:28:in `tagged' activesupport (5.2.4) lib/active_support/tagged_logging.rb:71:in `tagged' railties (5.2.4) lib/rails/rack/logger.rb:26:in `call' sprockets-rails (3.2.1) lib/sprockets/rails/quiet_assets.rb:13:in `call' actionpack (5.2.4) lib/action_dispatch/middleware/remote_ip.rb:81:in `call' actionpack (5.2.4) lib/action_dispatch/middleware/request_id.rb:27:in `call' rack (2.0.7) lib/rack/method_override.rb:22:in `call' rack (2.0.7) lib/rack/runtime.rb:22:in `call' activesupport (5.2.4) lib/active_support/cache/strategy/local_cache_middleware.rb:29:in `call' actionpack (5.2.4) lib/action_dispatch/middleware/executor.rb:14:in `call' actionpack (5.2.4) lib/action_dispatch/middleware/static.rb:127:in `call' rack (2.0.7) lib/rack/sendfile.rb:111:in `call' railties (5.2.4) lib/rails/engine.rb:524:in `call' puma (3.12.1) lib/puma/configuration.rb:227:in `call' puma (3.12.1) lib/puma/server.rb:660:in `handle_request' puma (3.12.1) lib/puma/server.rb:474:in `process_client' puma (3.12.1) lib/puma/server.rb:334:in `block in run' puma (3.12.1) lib/puma/thread_pool.rb:135:in `block in spawn_thread' ActionController::RoutingError (No route matches [GET] "/accepted/26/users.scss"): actionpack (5.2.4) lib/action_dispatch/middleware/debug_exceptions.rb:65:in `call' web-console (3.7.0) lib/web_console/middleware.rb:135:in `call_app' web-console (3.7.0) lib/web_console/middleware.rb:30:in `block in call' web-console (3.7.0) lib/web_console/middleware.rb:20:in `catch' web-console (3.7.0) lib/web_console/middleware.rb:20:in `call' actionpack (5.2.4) lib/action_dispatch/middleware/show_exceptions.rb:33:in `call' railties (5.2.4) lib/rails/rack/logger.rb:38:in `call_app' railties (5.2.4) lib/rails/rack/logger.rb:26:in `block in call' activesupport (5.2.4) lib/active_support/tagged_logging.rb:71:in `block in tagged' activesupport (5.2.4) lib/active_support/tagged_logging.rb:28:in `tagged' activesupport (5.2.4) lib/active_support/tagged_logging.rb:71:in `tagged' railties (5.2.4) lib/rails/rack/logger.rb:26:in `call' sprockets-rails (3.2.1) lib/sprockets/rails/quiet_assets.rb:13:in `call' actionpack (5.2.4) lib/action_dispatch/middleware/remote_ip.rb:81:in `call' actionpack (5.2.4) lib/action_dispatch/middleware/request_id.rb:27:in `call' rack (2.0.7) lib/rack/method_override.rb:22:in `call' rack (2.0.7) lib/rack/runtime.rb:22:in `call' activesupport (5.2.4) lib/active_support/cache/strategy/local_cache_middleware.rb:29:in `call' actionpack (5.2.4) lib/action_dispatch/middleware/executor.rb:14:in `call' actionpack (5.2.4) lib/action_dispatch/middleware/static.rb:127:in `call' rack (2.0.7) lib/rack/sendfile.rb:111:in `call' railties (5.2.4) lib/rails/engine.rb:524:in `call' puma (3.12.1) lib/puma/configuration.rb:227:in `call' puma (3.12.1) lib/puma/server.rb:660:in `handle_request' puma (3.12.1) lib/puma/server.rb:474:in `process_client' puma (3.12.1) lib/puma/server.rb:334:in `block in run' puma (3.12.1) lib/puma/thread_pool.rb:135:in `block in spawn_thread'
退会済みユーザー

退会済みユーザー

2019/12/16 09:16

accepted.html.erbファイルの39行目と40行目を見せてください
tori315

2019/12/16 09:25

以下39.40行目です。 <% @accepteds.reverse_each do | accepted| %> <% post = Post.find_by(id: accepted.post_id) %>
退会済みユーザー

退会済みユーザー

2019/12/16 09:48 編集

>新しく始めて、そのindexをクリックした辺りのlogです 「index」とはposts/indexのことですか?それともaccepted/:id/acceptedのことですか?
winterboum

2019/12/16 09:55

viewを見なおしてみました。 これ、indexでもって、 <%= form_tag("/accepted/#{@current_user.id}/accepted",method: :post,data:{confirm:"このクエストを受けますか?"}) do %> となってますね。これですとcurrent_user.idが必ず渡ってしまいます。 複数のpostが表示されていて、そのなかの「このpost」を選ぶのではないのでしょうか? すると <% @posts.each do |post| %>のloopのなかに、 "/accepted/#{post.id}/accepted" へのlinkを書くようにしなければなりません
tori315

2019/12/16 10:36

ありがとうございます。 出来ました! 胸がスッキリしました。
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.36%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問