0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

エラー発生→解決済【備忘録】

Posted at

今日困ってやっと解決した件

'''class PrototypesController < ApplicationController
before_action :authenticate_user!, except: [:index, :show] #トップページと詳細以外はログインしている人だけ
before_action :move_to_index, only: [:edit]

def index
@prototypes = Prototype.includes(:user).order("created_at DESC")
end

省略

def prototype_params
params.require(:prototype).permit(:title, :catch_copy, :image, :concept).merge(user_id: current_user.id)♯prototypeはid要らない。userだけmergeする。
end

def move_to_index
@prototype = Prototype.find(params[:id])
unless @prototype.user == current_user ♯4行目でログインしてないユーザーは入れない(トップページと詳細ページ除く)はここに来て、prototypeとログインユーザー同じじゃなかったらトップページに飛ぶ。
redirect_to action: :index
end
end
end'''

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?