title: Passing instance variable from controller to view in rails
body: <p>I have a user profile controller called "userinfo" and it's corresponding view. The userinfo index is the root path. In the homepage(which is the userinfo index), I have a link that takes you to the user profile page. It is giving me this error when I click on the image on the view page:<a href="https://i.stack.imgur.com/Sevn5.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Sevn5.png" alt="enter image description here"></a>
  My routes are:<a href="https://i.stack.imgur.com/wanaz.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/wanaz.png" alt="enter image description here"></a>
  My userinfos_controller:</p>
  
  <pre><code>class UserinfosController &lt; ApplicationController
      before_action :find_userinfo, only: [:show, :edit, :update, :destroy]
      before_action :authenticate_user!
  
      def index
          @userinfors = Userinfo.where(:userinfo_id =&gt; @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
  </code></pre>
  
  <p>and my view is:</p>
  
  <pre><code>&lt;%= link_to image_tag("student.png", class: 'right'), userinfo_path(@userinfors) %&gt;
  </code></pre>
  
  <p>I thought maybe I must include ':index' in the 'before_action :find_userinfo' at the top of my controller. If I do that, the homepage doesn't even load and it gives me this error:<a href="https://i.stack.imgur.com/ARoEb.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ARoEb.png" alt="enter image description here"></a></p>