Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8868127
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T17:11:35+00:00 2026-06-14T17:11:35+00:00

I am trying to use the link_to feature to link one view to another.

  • 0

I am trying to use the link_to feature to link one view to another.

The view i am calling link_to is app/views/instructors/show.html.erb and that snippet of code looks like this (namely, the second to last line of it)

<% provide(:title, @instructor.login) %>
<% courses = Course.where(:instructor_ID => @instructor.id) %>
    <div class="span2">
      <h1 align=center ><%= @instructor.login %></h1>
      <%= link_to "Add course", new_course_path(:instructor_ID\
                => @instructor.id), :class => "btn" %>
        <br>
        <br>
        <%= link_to "Remove course", delete_course_path(courses), :class => "btn"%>
    </div>

The view I am trying to link to is is app/views/courses/show_all.html.erb and looks like this:

<% @courses.each do |course| %>
  <tr>
    <td><%= course.course_name %></td>
    <td><%= course.instructor_ID %></td>
    <td><%= link_to 'Show', course %></td>
    <td><%= link_to 'Edit', edit_course_path(course) %></td>
    <td><%= link_to 'Destroy', course, :method => :delete, :data => { :confirm => 'Are you sure?' } %></td>
  </tr>

delete_course_path routes to app/views/courses/show_all.html.erb shown above. When I try the code above, I get the following error:

undefined method `each’ for nil:NilClass

At this line:

<% @courses.each do |course| %>

Any ideas what i’m missing in my link_to?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T17:11:36+00:00Added an answer on June 14, 2026 at 5:11 pm

    In your show_all action, you should define a @courses instance variables. This is

    <% courses = Course.where(:instructor_ID => @instructor.id) %>

    not passed to show_all.html.erb.

    An instance variables is a variable passed from action of controller to the view corresponding.

    I suppose when you show page of instructor, your route will like this: /instructors/:id, so maybe in your show_all action of instructor controller, you need something like:

    def show_all
      @courses = Course.where(instructor_ID: params[:id])
      render 'courses/show_all'
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to use the jquery UI tab feature from the link http://jqueryui.com/demos/tabs/manipulation.html
I'm trying to link the LizardTech GeoExpress DSDK into my own application. I use
I am need paint my image. I'm trying use JQuery in here this link:
I'm trying use mod_rewrite to rewrite URLs from the following: http://www.site.com/one-two-file.php to http://www.site.com/one/two/file.php The
I am trying use a Java Uploader in a ROR app (for its ease
trying to use hibernate with my web app and getting following exception: Initial SessionFactory
I'm trying to use EF4 and the supposedly new feature of having GUIDs generated
I'm trying to use the sort feature when querying my mongoDB, but it is
I am trying to use the customisable property tab feature of the WinForms PropertyGrid
I'm trying to use the new chrome inline install feature for extensions (see here:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.