Hi, im new to rails and I got a mind boggling issue.
I have a select form populated with Institutes names e.g University of
Yale. These records are obtained from the Institute ActiveRecord.The
institutes table has a many to many relationships with the course table.
My application should work such that when you select a certain institute
using a select() component and press the button proceed to view courses
available for the institute chosen. This will take you to a new page
with the courses.
My problem is that i don’t know how i will store selected institute id
and use it to select specific courses using the many to many
relationships… below are my code snippets
/app/controller/Course.rb
class CourseController < ApplicationController
layout ‘standard’
def list
@courses = Course.find(:all)
end
def show
@course = Course.find(params[:id])
end
def new
@courses = Course.new
@institutes = Institute.find(:all)
# @cfilters = CourseFilter.find(params[:id])
end
def create
@course = Course.new(params[:course])
if @course.save
redirect_to :action => ‘list’
else
flash[:warning]="Failed to "
@courses = Course.find(:all)
render :action => ‘new’
end
end
end
==========================================================================
/app/views/institute/list.html.erb
<% if @institutes.blank? %>
There are not any institutes currently in the system.
<% else %>Select your chosen Institution
<%= select ("submit", "name", Institute.find(:all).collect {|c| [ c.name, c.id ] }, :prompt => "Select Institute", :onchange => "this.form.submit();")%><%= submit_tag “Proceed To Courses”%>
<%end%><%= link_to “Add new College”, {:action => ‘new’ }%>
/app/views/courses/list.html.erb
<% if @courses.blank? %>
There are not any courses currently in the system.
<% else %>Select your chosen Course
-
<% Course.find(params[:id]).each do |c| %>
- <%= link_to c.course_name, :action => "show", :id => c.id %> <% end %>
<%= link_to "Add new College", {:action => 'new' }%>
=======================================================================Would really need you help people. Thanx