初めて質問します。
Ruby on Railsで簡単な単語帳アプリを制作しています。
indexのビューページに遷移しようとしたところエラーが発生しました。
ご回答のほどよろしくお願い致します。
発生している問題・エラーメッセージ
ActionController::UrlGenerationError in Words#index Showing /Users/hayashiryouware/projects/words/app/views/words/index.html.haml where line #15 raised: No route matches {:action=>"edit", :controller=>"words", :group_id=>10}, missing required keys: [:id]
.word_register .register_btn = link_to '単語登録', new_group_word_path, class:'btn-register' - @words.each do |word| .folk .center .textblock .word = word.word .meaning = word.meaning .image = image_tag word.image.url if word.image? .btnblock = link_to '編集', edit_group_word_path(word.id), class:"edit" = link_to '削除', '{/groups/:group_id/words/:id}', method: :delete, class:"delete" .sentence = word.sentence
class WordsController < ApplicationController #before_action :move_to_index, except: [:index, :search] def index @group = Group.find(params[:group_id]) @words = @group.words #@search = Word.ransack(params[:q]) #@words = @search.result end def new @words = Word.new end def create @words = Word.create(word_params) redirect_to group_words_path end def edit @groups = Group.find(word_params[:group_id]) @word = @groups.words end def destroy word = Word.find(params[:id]) word.destroy redirect_to root_path end private def word_params params.require(:word).permit(:word, :meaning, :sentence, :image).merge(user_id: current_user.id, group_id: params[:group_id]) end end
Ruby
試したこと
= link_to '編集', edit_group_word_path(word.id), class:"edit" のルートが
原因だと思い試行錯誤してみましたが、解決には至りませんでした。
補足情報(FW/ツールのバージョンなど)
ここにより詳細な情報を記載してください。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2020/02/28 09:45