###前提・実現したいこと
Ruby のRouting Errorについて質問です。
_pictuer投稿サイトを作成中で、編集機能を追加し、投稿下絵のコメントを編集するためeditを押下したところエラーになりました。
###発生している問題・エラーメッセージ
Routing Error No route matches [GET] "/tweets/1edit" Rails.root: /Users/○○/projects/For_Study_Rails/pictweet Application Trace | Framework Trace | Full Trace Routes Routes match in priority from top to bottom 〜
###該当のソースコード
〜 tweets_controller.rb 〜
Ruby
1class TweetsController < ApplicationController 2 before_action :move_to_index, except: :index 3 4 def index 5 @tweets = Tweet.includes(:user).order("created_at DESC").page(params[:page]).per(5) 6 end 7 8 def new 9 end 10 11 def create 12 Tweet.create(image: tweet_params[:image], text: tweet_params[:text], user_id: current_user.id) 13 end 14 15 def destroy 16 tweet = Tweet.find(params[:id]) 17 if tweet.user_id == current_user.id 18 tweet.destroy 19 end 20 end 21 22 def edit 23 @tweet = Tweet.find(params[:id]) 24 end 25 26 def update 27 tweet = Tweet.find(params[:id]) 28 if tweet.user_id == current_user.id 29 tweet.update(tweet_params) 30 end 31 end 32 33 private 34 def tweet_params 35 params.permit(:image, :text) 36 end 37 38 def move_to_index 39 redirect_to action: :index unless user_signed_in? 40 end 41end
〜 routes.rb 〜
Rails.application.routes.draw do devise_for :users root 'tweets#index' get 'tweets' => 'tweets#index' get 'tweets/new' => 'tweets#new' post 'tweets' => 'tweets#create' delete 'tweets/:id' => 'tweets#destroy' patch 'tweets/:id' => 'tweets#update' get 'tweets/:id/edit' => 'tweets#edit' get 'users/:id' => 'users#show' end
〜 index.html.haml 〜
.contents.row - @tweets.each do |tweet| .content_post{:style => "background-image: url(#{tweet.image});"} - if user_signed_in? && current_user.id == tweet.user_id .more %span= image_tag 'arrow_top.png' %ul.more_list %li = link_to '編集', "/tweets/#{tweet.id}/edit", method: :get %li = link_to '削除', "/tweets/#{tweet.id}", method: :delete = simple_format(tweet.text) %span.name %a{:href => "/users/#{tweet.user_id}"} %span 投稿者 = tweet.user.nickname = paginate(@tweets)
〜 edit.html.haml 〜
.contents.row = form_tag("/tweets/#{@tweet.id}", method: :patch ) do %h3 編集する %input{:autofocus => "true", :name => "image", :placeholder => "Image Url", :type => "text", :value => @tweet.image}/ %textarea{:cols => "30", :name => "text", :placeholder => "text", :rows => "10"}= @tweet.text %input{:type => "submit", :value => "SEND”>
〜 update.html.haml 〜
.contents.row .success %h3 更新が完了しました。 %a.btn{:href => "/"}投稿へ戻る
###試したこと
_Routing Error No route matches [GET] "/tweets/1edit" に似たエラーの記事を二、三見ましたが、恥ずかしながら解消に至りませんでした。
_スペルミスもないと「思います」。
_"/tweets/1edit"については、教材によりますと、destroyと同じく、編集画面のパスはツイートごとに異なるため :id のような書き方をするとのことですが、destroyと違ってパスになぜ/edit が付くのかは詳しくはわかりません。
###補足情報(言語/FW/ツール等のバージョンなど)
https://github.com/Timegoesveryswiftly/pictweet/commit/aa219774d7f4500a47951470c811fc170dc16a17
_なにがしかのアドバイスをいただくことができますと幸いです。

回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/03/23 06:33 編集
退会済みユーザー
2017/03/27 05:25