mardi 11 juin 2019

get the id from url and use it to get a specific data from a table

I am doing a project for my studies. How can I get the id from the URL and pass it to the controller to get specific data from the table

This some of codes I have tried

class MajorsController < ApplicationController
  before_action :set_major, only: [:show, :edit, :update, :destroy]

  # GET /majors
  # GET /majors.json
  def index
    @majors = Major.all
  end

  # GET /majors/1
  # GET /majors/1.json
  def show
    @majors = Major.all
    @courses = Course.where(params[:major_id])
  end

i expect the output is the only two courses i have but it output them all

Aucun commentaire:

Enregistrer un commentaire