I'm using Bootstrap with a Rails application. I want a div with class .container on the home page and all post show pages. Every other page should have class .container-fluid. I'm trying to accomplish this with javascript in a js.erb file located in app/assets/javascripts. If the path is "/" or "/posts/:id" I will remove class .container-fluid and add class .container to id #wrapper else I will remove class .container and add class .container-fluid. I can't figure out how to do this with all post ids, but I can do it with a specific post id. I've used route helpers in the asset pipeline to get this far. My code below successfully changes the class of post with id 1 to .container. How would I change any post show page to class .container? Any suggestions would be appreciated.
dashboard.js.erb
function wrapperClass() {
var path = window.location.pathname;
<% url = Rails101primer::Application.routes.url_helpers %>
var root_path = "<%= url.root_path %>";
var post_path = "<%= CGI.unescape url.post_path(1) %>";
if (path == root_path || path == post_path) {
jQuery('#wrapper').removeClass('container-fluid');
jQuery('#wrapper').addClass('container');
} else {
jQuery('#wrapper').removeClass('container');
jQuery('#wrapper').addClass('container-fluid');
};
};
jQuery(document).ready( function () {
wrapperClass();
jQuery(document).on('page:load', function () {
wrapperClass();
});
});