How to carry a variable from one page to another

Viewed 20

Kinda new to ruby, rails and devise but i'm trying to make a website where users(student) are enrolled in courses, which has its own unique id.

On my loggedin user home page I have a list that displays all courses the student is enrolled in, that pairs the student id to course id on the enrollment table.

<td><%= enrolment.course_id %></td>
<td><%= link_to "Complete Course", home_completeTask_path, class:"btn btn-dark" %></td>

The code I have in my for loop to fill the table of courses the student is enrolled in.

I would like to take enrolment.course_id value from here to home_completeTask where it is used to display the course modules and tasks.

In appllication controller

I have declared a variable:

@Cid

I havn't set it to anything as it would change depending on what the user clicks.

In Home controller

Both pages are in the home directory, and tried to define a method there.

def courseComplete(cid)
   link_to "Complete Course", home_completeTask_path, class:"btn btn-dark"
   @Cid = (cid)
end

This method didn't work and honestly I can't figure out another way to user that variable.

Any suggestions on this would be great, thanks.

1 Answers

You can pass any parameter as below.

<td><%= enrolment.course_id %></td>
<td><%= link_to "Complete Course", home_completeTask_path(course_id: enrolment.course_id), class:"btn btn-dark" %></td>

and in controllers method you will get same under params[:course_id].

Related