質問をすることでしか得られない、回答やアドバイスがある。

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

新規登録して質問してみよう
ただいま回答率
85.48%
Ruby on Rails 3.2.0

Ruby on Railsは、Rubyにより構築されたオープンソースのWebアプリケーションフレームワークである。 version 3.2.0は2012年1月2日にリリースされた。

Q&A

0回答

461閲覧

いいね機能について作動しない

ahdho

総合スコア0

Ruby on Rails 3.2.0

Ruby on Railsは、Rubyにより構築されたオープンソースのWebアプリケーションフレームワークである。 version 3.2.0は2012年1月2日にリリースされた。

0グッド

0クリップ

投稿2022/02/16 12:29

No route matches [POST] "/tweets/4/favorites/4"
このエラーが出てしまいます。

routes.rb

1Rails.application.routes.draw do 2 devise_for :users 3 # For details on the DSL available within this file, see https://guides.rubyonrails.org/routing.html 4 root to: 'tweets#index' 5resources :tweets do 6 resources :comments, only:[:create, :destroy] 7 resources :favorites, only: [ :create,:destroy] 8 collection do 9 get 'search' 10 end 11 end 12 resources :users, only: :show 13end

show.html.erb

1<div class="contents row"> 2 <div class="content_post" style="profile_image_id: url(<%= @tweet.profile_image_id %>);"> 3 <% if user_signed_in? && current_user.id == @tweet.user_id %> 4 <div class="more"> 5 <ul class="more_list"> 6 <li> 7 <%= link_to '編集', edit_tweet_path(@tweet.id), method: :get %> 8 </li> 9 <li> 10 <%= link_to '削除', tweet_path(@tweet.id), method: :delete %> 11 </li> 12 </ul> 13 </div> 14 <% end %> 15 16 <div class="col"><%= attachment_image_tag @tweet, :profile_image, format: 'jpeg', size: '300x300' %></div> 17 <div class="col"><%= @tweet.text %></div> 18 19 <span class="name"> 20 <a href="/users/<%= @tweet.user.id %>"> 21 <span>投稿者</span><%= @tweet.user.nickname %> 22 </a> 23 </span> 24 </div> 25 <% if @tweet.favorited_by?(current_user) %> 26 <%= button_to tweet_favorite_path(@tweet), method: :DELETE do %> 27 <i class="fa fa-heart" aria-hidden="true" style="color: red;"></i> 28 <%= @tweet.favorites.count %>like 29 <% end %> 30<% else %> 31 <%= button_to tweet_favorites_path(@tweet) , method: :POST do %> 32 <i class="fa fa-heart-o" aria-hidden="true"></i> 33 <%= @tweet.favorites.count %>like 34 <% end %> 35<% end %> 36 <div class="container"> 37 <% if user_signed_in? %> 38 <%= form_with(model: [@tweet, @comment], local: true) do |form| %> 39 <%= form.text_area :text, placeholder: "コメントする", rows: "2" %> 40 <%= form.submit "SEND" %> 41 <% end %> 42 <% else %> 43 <strong><p>※※※ コメントの投稿には新規登録/ログインが必要です ※※※</p></strong> 44 <% end %> 45 <div class="comments"> 46 <h4><コメント一覧></h4> 47 <% if @comments %> 48 <% @comments.each do |comment| %> 49 <p> 50 <strong><%= link_to comment.user.nickname, "/users/#{comment.user_id}" %>:</strong> 51 <%= comment.text %> 52 </p> 53 <% end %> 54 <% end %> 55 </div> 56 </div> 57</div>
Prefix Verb URI Pattern Controller#Action new_user_session GET /users/sign_in(.:format) devise/sessions#new user_session POST /users/sign_in(.:format) devise/sessions#create destroy_user_session GET /users/sign_out(.:format) devise/sessions#destroy new_user_password GET /users/password/new(.:format) devise/passwords#new edit_user_password GET /users/password/edit(.:format) devise/passwords#edit user_password PATCH /users/password(.:format) devise/passwords#update PUT /users/password(.:format) devise/passwords#update POST /users/password(.:format) devise/passwords#create cancel_user_registration GET /users/cancel(.:format) devise/registrations#cancel new_user_registration GET /users/sign_up(.:format) devise/registrations#new edit_user_registration GET /users/edit(.:format) devise/registrations#edit user_registration PATCH /users(.:format) devise/registrations#update PUT /users(.:format) devise/registrations#update DELETE /users(.:format) devise/registrations#destroy POST /users(.:format) devise/registrations#create root GET / tweets#index tweet_comments POST /tweets/:tweet_id/comments(.:format) comments#create tweet_comment DELETE /tweets/:tweet_id/comments/:id(.:format) comments#destroy tweet_favorites POST /tweets/:tweet_id/favorites(.:format) favorites#create tweet_favorite DELETE /tweets/:tweet_id/favorites/:id(.:format) favorites#destroy search_tweets GET /tweets/search(.:format) tweets#search tweets GET /tweets(.:format) tweets#index POST /tweets(.:format) tweets#create new_tweet GET /tweets/new(.:format) tweets#new edit_tweet GET /tweets/:id/edit(.:format) tweets#edit tweet GET /tweets/:id(.:format) tweets#show PATCH /tweets/:id(.:format) tweets#update PUT /tweets/:id(.:format) tweets#update DELETE /tweets/:id(.:format) tweets#destroy user GET /users/:id(.:format) users#show refile_app /attachments #<Refile::App app_file="/home/ec2-user/.rvm/gems/ruby-2.6.5/bundler/gems/refile-46b4178654e6/lib/refile/app.rb">

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

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

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

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

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

guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだ回答がついていません

会員登録して回答してみよう

アカウントをお持ちの方は

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

ただいまの回答率
85.48%

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

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

質問する

関連した質問