現在ruby on railsでWebアプリケーションを作成しています。テキストを編集してupdateでredirect_toでエラーが出てしまいます。
エラー
Routing Error Routes match in priority from top to bottom
ルーティング
Rails.application.routes.draw do root to: 'toppages#index' resources :sessions, only: [:new, :create, :destroy] resources :users, only: [:index, :show, :new, :create] resources :novels, only: [:new, :edit, :update, :create, :destroy] end
コントローラー
class NovelsController < ApplicationController before_action :require_user_logged_in before_action :correct_user, only: [:destroy] def new @novel = Novel.new end def edit @novel = Novel.find(params[:id]) end def update @novel = Novel.find(params[:id]) if @novel.update(novel_params) flash[:success] = '小説は正常に更新されました' redirect_to @novel else flash.now[:danger] = '小説は更新されませんでした' render :edit end end def create @novel = current_user.novels.build(novel_params) if @novel.save flash[:success] = '小説を保存しました' redirect_to root_url else @novels = current_user.novels.order(id: :desc).page(params[:page]) flash.now[:danger] = '小説の投稿に失敗しました' render 'toppages/index' end end def destroy @novel.destroy flash[:success] = '小説を削除しました' redirect_back(fallback_location: root_path) end private def novel_params params.require(:novel).permit(:title, :content) end def correct_user @novel = current_user.novels.find_by(id: params[:id]) unless @novel redirect_to root_url end end end
ビュー
<% novels.each do |novel| %> <%= novel.title %> <%= novel.content %> <% if current_user == novel.user %> <%= link_to 'この小説を編集する', edit_novel_path(novel) %> <%= link_to "削除", novel, method: :delete, data: { confirm: "本当に削除してもよろしいでしょうか?" }, class: 'btn btn-danger btn-sm' %> <% end %> <% end %> <%= paginate novels %>
ルーティングエラーが出てしまいます。泣き崩れそうです。ご教授いただければ幸いです。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/08/21 12:46
2019/08/21 13:08
2019/08/21 13:12
2019/08/21 13:56