0

I have the following link_to helper:

 <div class="button_wrapper"><%= link_to "View Course", [course.grade, course], :class => "course_button" %></div>

and I would like to be able to change the :class => "course_button" depending on which Subject the Course belongs to which I can specify when creating a new course. So basically I want the button to change color depending on which Subject it belongs to, for example Math will be blue and Chemistry will be green. The way im aiming to achieve this (which may not be the best way) is to create different styling in css for each subject, and then I would like the Subject name to be inputed dynamically in the :class, so the end result will be something like this if I choose maths:

<div class="button_wrapper"><%= link_to "View Course", [course.grade, course], :class => "Math_button" %></div>

How can I achieve this?

Ryan K
  • 3,985
  • 4
  • 39
  • 42
  • Possible duplicate of [Style – Ryan K Apr 01 '16 at 11:54

1 Answers1

2

I would be like this :

<div class="button_wrapper"><%= link_to "View Course", [course.grade, course], :class => "#{course.subject.name}_button" %></div>
Muhammad Ali
  • 2,173
  • 15
  • 20
  • Hey thanks for the response. Just wondering how this solution works? if I choose chemistry as a subject will the class be set to Chemistry_button? could you explain how this works? – Rashed Al-Julaibi Apr 02 '16 at 09:20
  • 1
    I managed to solve it with the following code `<%= link_to "View Course", [course.grade, course], :class => "#{course.subject.name}_button" %>`. Your asnwer led me in the right direction so thanks :) – Rashed Al-Julaibi Apr 02 '16 at 09:33