In my rails app I have user, school, and course models. I have set up a polymorphic association so that users and schools have many courses as hostable, and the course belongs_to hostable. My routes look like this:
resources :users do
resources :courses
end
resources :schools do
resources :courses
end
The show in my school controller looks like this:
def show
@school = School.find(params[:id])
@user = current_user.schools.find_by_user_id(params[:user_id])
@title = @school.school_name
@hostable = @school
@courses = @hostable.courses
@course = Course.new
end
The courses partial that renders in the school and user show page looks like this:
<div id="courses">
<% @courses.each do |course| %>
<div class="course">
<%= simple_format course.title %>
<%= simple_format course.description %>
</div>
<% end %>
</div>
Right now I only have the school view configured to simply list the course title and description. What I want to do is list all of the school’s courses on the school’s show page, and instead of only showing the text of the course title, I want the course title to be a link which re-directs to the course’s page. Any suggestions?
Thanks.
1 Answer