Note that there are some explanatory texts on larger screens.

plurals
  1. POHighlight the title and release header
    primarykey
    data
    text
    <p>I'm trying to highlight a title header or release date header every time you click on it, but i can't make it. I'm using Ruby 1.9.3 and Rails 3.2.14</p> <p>I thought it was something in my controller or view, but i don't get it. It sorts, but the yellow highlight is not applied in the header.</p> <p>Here it is my movies_controller file (just the relevant part):</p> <pre><code>class MoviesController &lt; ApplicationController ... def index @movies = Movie.find(:all, :order =&gt; params[:sort_by]) if params[:sort_by] == 'title' @title_header = 'hilite' elsif params[:sort_by] == 'release_date' @release_header ='hilite' end end ... </code></pre> <p>My view file (is HAML):</p> <pre><code>-# This file is app/views/movies/index.html.haml %h1 All Movies %table#movies %thead %tr %th{:class=&gt;@title_header, :id=&gt; "title_header"}= link_to "Movie Title", movies_path(:sort_by =&gt; 'title') %th Rating %th{:class=&gt;@release_header, :id=&gt; "release_date_header"}= link_to "Release Date", movies_path(:sort_by =&gt; 'release_date') %th More Info %tbody - @movies.each do |movie| %tr %td= movie.title %td= movie.rating %td= movie.release_date %td= link_to "More about #{movie.title}", movie_path(movie) = link_to 'Add new movie', new_movie_path </code></pre> <p>And Finally, my application.css:</p> <pre><code>html, body { margin: 0; padding: 0; background: White; color: DarkSlateGrey; font-family: Tahoma, Verdana, sans-serif; font-size: 10pt; } div#main { margin: 0; padding: 0 20px 20px; } a { background: transparent; color: maroon; text-decoration: underline; font-weight: bold; } h1 { color: maroon; font-size: 150%; font-style: italic; display: block; width: 100%; border-bottom: 1px solid DarkSlateGrey; } h1.title { margin: 0 0 1em; padding: 10px; background-color: orange; color: white; border-bottom: 4px solid gold; font-size: 2em; font-style: normal; } table#movies { margin: 10px; border-collapse: collapse; width: 100%; border-bottom: 2px solid black; } table#movies th { border: 2px solid white; font-weight: bold; background-color: wheat; } table#movies th.hilite { background-color: yellow; } table#movies th, table#movies td { padding: 4px; text-align: left; } #notice #warning { background: rosybrown; margin: 1em 0; padding: 4px; } form label { display: block; line-height: 25px; font-weight: bold; color: maroon; } </code></pre> <p>UPDATE: HTML source after rendering:</p> <pre><code>&lt;!DOCTYPE html&gt; &lt;html&gt; &lt;head&gt; &lt;title&gt;Rotten Potatoes!&lt;/title&gt; &lt;link href="/assets/application.css?body=1" media="screen" rel="stylesheet" type="text/css" /&gt; &lt;script src="/assets/jquery.js?body=1" type="text/javascript"&gt;&lt;/script&gt; &lt;script src="/assets/jquery_ujs.js?body=1" type="text/javascript"&gt;&lt;/script&gt; &lt;script src="/assets/application.js?body=1" type="text/javascript"&gt;&lt;/script&gt; &lt;meta content="authenticity_token" name="csrf-param" /&gt; &lt;meta content="jJOoNtKNLzZb+w8ywbDStDxk5TbODkv8fUtgX1bEvFU=" name="csrf-token" /&gt; &lt;/head&gt; &lt;body&gt; &lt;h1 class='title'&gt;Rotten Potatoes!&lt;/h1&gt; &lt;div id='main'&gt; &lt;h1&gt;All Movies&lt;/h1&gt; &lt;table id='movies'&gt; &lt;thead&gt; &lt;tr&gt; &lt;th id='title_header'&gt;&lt;a href="/movies?sort_by=title"&gt;Movie Title&lt;/a&gt;&lt;/th&gt; &lt;th&gt;Rating&lt;/th&gt; &lt;th id='release_date_header'&gt;&lt;a href="/movies?sort_by=release_date"&gt;Release Date&lt;/a&gt;&lt;/th&gt; &lt;th&gt;More Info&lt;/th&gt; &lt;/tr&gt; &lt;/thead&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;Star Wars&lt;/td&gt; &lt;td&gt;PG&lt;/td&gt; &lt;td&gt;1977-05-02 00:00:00 UTC&lt;/td&gt; &lt;td&gt;&lt;a href="/movies/1"&gt;More about Star Wars&lt;/a&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;Aladdin&lt;/td&gt; &lt;td&gt;G&lt;/td&gt; &lt;td&gt;1992-11-25 00:00:00 UTC&lt;/td&gt; &lt;td&gt;&lt;a href="/movies/2"&gt;More about Aladdin&lt;/a&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;The Terminator&lt;/td&gt; &lt;td&gt;R&lt;/td&gt; &lt;td&gt;1984-10-26 00:00:00 UTC&lt;/td&gt; &lt;td&gt;&lt;a href="/movies/3"&gt;More about The Terminator&lt;/a&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;When Harry Met Sally&lt;/td&gt; &lt;td&gt;R&lt;/td&gt; &lt;td&gt;1989-07-21 00:00:00 UTC&lt;/td&gt; &lt;td&gt;&lt;a href="/movies/4"&gt;More about When Harry Met Sally&lt;/a&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;The Help&lt;/td&gt; &lt;td&gt;PG-13&lt;/td&gt; &lt;td&gt;2011-08-10 00:00:00 UTC&lt;/td&gt; &lt;td&gt;&lt;a href="/movies/5"&gt;More about The Help&lt;/a&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;Chocolat&lt;/td&gt; &lt;td&gt;PG-13&lt;/td&gt; &lt;td&gt;2001-01-05 00:00:00 UTC&lt;/td&gt; &lt;td&gt;&lt;a href="/movies/6"&gt;More about Chocolat&lt;/a&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;Amelie&lt;/td&gt; &lt;td&gt;R&lt;/td&gt; &lt;td&gt;2001-04-25 00:00:00 UTC&lt;/td&gt; &lt;td&gt;&lt;a href="/movies/7"&gt;More about Amelie&lt;/a&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;2001: A Space Odyssey&lt;/td&gt; &lt;td&gt;G&lt;/td&gt; &lt;td&gt;1968-04-06 00:00:00 UTC&lt;/td&gt; &lt;td&gt;&lt;a href="/movies/8"&gt;More about 2001: A Space Odyssey&lt;/a&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;The Incredibles&lt;/td&gt; &lt;td&gt;PG&lt;/td&gt; &lt;td&gt;2004-11-05 00:00:00 UTC&lt;/td&gt; &lt;td&gt;&lt;a href="/movies/9"&gt;More about The Incredibles&lt;/a&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;Raiders of the Lost Ark&lt;/td&gt; &lt;td&gt;PG&lt;/td&gt; &lt;td&gt;1981-06-12 00:00:00 UTC&lt;/td&gt; &lt;td&gt;&lt;a href="/movies/10"&gt;More about Raiders of the Lost Ark&lt;/a&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;Chicken Run&lt;/td&gt; &lt;td&gt;G&lt;/td&gt; &lt;td&gt;2000-06-21 00:00:00 UTC&lt;/td&gt; &lt;td&gt;&lt;a href="/movies/11"&gt;More about Chicken Run&lt;/a&gt;&lt;/td&gt; &lt;/tr&gt; &lt;/tbody&gt; &lt;/table&gt; &lt;a href="/movies/new"&gt;Add new movie&lt;/a&gt; &lt;/div&gt; &lt;/body&gt; &lt;/html&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload