"userinfo"というユーザープロファイルコントローラがあり、それに対応するビューがあります。 userinfoインデックスはルートパスです。ホームページ(userinfoインデックス)には、ユーザープロフィールページにリンクするリンクがあります。 マイuserinfos_controller:
私のルートは以下のとおりです。コントローラからインスタンス変数をレールに渡す
class UserinfosController < ApplicationController
before_action :find_userinfo, only: [:show, :edit, :update, :destroy]
before_action :authenticate_user!
def index
@userinfors = Userinfo.where(:userinfo_id => @userinformation_user_id)
end
def show
@myvideo = Video.last
end
def new
@userinformation = current_user.userinfos.build
end
def create
@userinformation = current_user.userinfos.build(userinfo_params)
if @userinformation.save
redirect_to root_path
else
render 'new'
end
end
def edit
end
def update
end
def destroy
@userinformation.destroy
redirect_to userinfo_path
end
private
def userinfo_params
params.require(:userinfo).permit(:name, :email, :college, :gpa, :major)
end
def find_userinfo
@userinformation = Userinfo.find(params[:id])
end
end
と私の見解は以下のとおりです。
<%= link_to image_tag("student.png", class: 'right'), userinfo_path(@userinfors) %>
が、私は多分思った私は、ビュー・ページ上の画像をクリックしたとき、それは私に、このエラーを与えています私は ':index_'を 'before_action:find_userinfo'の中に入れてください。私はそれを行う場合は、ホームページにもロードされないと、それは私に、このエラーを与える:
お元気ですか、コントローラで何か変更しましたか?また、コントローラの「before_action」に「:index」を追加する必要がありますか? – Dinukaperera
@Dinukapereraあなたはinstace変数の代わりにidを渡さなければなりませんuserinformation_user_id – puneet18