我有一个名为“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) %>
我想,也许我必须在控制器顶部的'before_action:find_userinfo'中包含':index'。如果我这样做,网页甚至不加载,这让我这个错误:
嗨,你有没有改变控制器中的任何东西?另外,我应该在控制器的“before_action”中添加':index'吗? – Dinukaperera
@Dinukaperera你必须通过id而不是instace变量userinformation_user_id – puneet18