I am trying to use the tabs function from jQuery UI in a Rails app. I am using a helper for the navigation and I would like to keep it that way. The code in my helper is:
def links_for_navigation
html = ""
html = <<HTML
<ul>
<li><a href="#tabs-1">Courses</a></li>
<li><a href="#tabs-2">Parts</a></li>
<li><a href="#tabs-3">Categories</a></li>
</ul>
<div id="tabs-1"><% link_to "Courses", courses_path %>
<div id="tabs-2"><% link_to "Parts", parts_path %>
<div id="tabs-3"><% link_to "Categories", categories_path %>
HTML
end
My view pulls in the code with <% links_for_navigation %>
I added to my application.js:
jQuery(function() {
jQuery("#tabs").tabs();
});
And my application.html.erb has:
<%= stylesheet_link_tag 'courses', 'jquery-ui-1.8.13.custom.css' %>
<%= javascript_include_tag :defaults %>
<%= javascript_include_tag 'jquery-1.5.1.min.js', 'jquery-ui-1.8.13.custom.min.js', 'application' %>
When I try to load the page I get cannot find string HTML before EOF. What am I doing wrong?
I recommend using a partial, rather than a helper method. The partial, I’ll call it
_nav.html.erb, would look like the following (note theid="tabs"on the surroundingdiv):Then in the appropriate view file, you can insert the partial with a call to render:
I’ve never used jQuery tabs but try adding this to
application.js, based on this example. The"#tabs"selector inside$()corresponds to theid="tabs"from above:I’ll offer a couple tips/reminders as well:
=if you want them to print something, i.e.<%= @user.name %>versus<% @user.name %>. The first will output a string into the file, the second will not. There are cases where you might not want to print something, so you would leave off the=.*.html.erbfiles. This isn’t a golden rule, but it’s a good rule of thumb.