前提・実現したいこと
現在ドットインストールを利用してrailsのアプリを作っているのですが、リダイレクトがうまくいきません。
発生している問題
記事の詳細画面 例 /post/1 でコメントした時に /posts.1 というURLになり、記事一覧 /posts にリダイレクトされます。
該当のソースコード
posts_contloller.rb
ruby
1class PostsController < ApplicationController 2 3 def index 4 @posts = Post.all.order(created_at: 'desc') 5 end 6 7 def show 8 @post = Post.find(params[:id]) 9 end 10 11def new 12 @post = Post.new 13end 14 15def create 16# render plain: palams[:post].inspect 17@post = Post.new(post_params) 18if @post.save 19 redirect_to posts_path 20 else 21 #render plain: @post.errors.inspect 22 render 'new' 23 end 24end 25 26def destroy 27 @post = Post.find(params[:id]) 28 @post.destroy 29 redirect_to posts_path 30end 31 32 def edit 33 @post = Post.find(params[:id]) 34 end 35 36def update 37 @post = Post.find(params[:id]) 38 if @post.update(post_params) 39 redirect_to posts_path 40 else 41 render 'edit' 42 end 43 end 44 45 46private 47def post_params 48params.require(:post).permit(:title, :body) 49end 50end 51
補足情報(FW/ツールのバージョンなど)
windows 10
vagrant 2.1.2
CentOS 6.8
ruby 2.5.1
rails 5.2.1
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。