1

I have a Rails 3 application that is using the 960 grid CSS layout(s). There are a couple of different views that stretch in width and I am trying to come up with a good way to dynamically change out those classes.

For Example: My Devise Controllers (Sessions, Passwords, etc) all use a certain class to restrict the width to 340px, while most of my other controllers use another class to restrict the width to 540px

So my 340px layout uses class names grid_6 push_5, while my 540px layout uses grid_10 push_3

Anyway to grab the accessed controller in the application_controller? My thinking is to just get the controller and have a switch statement that sets the class names in a helper_method.

Thoughts?

1 Answer 1

1

I was able to figure it out, thanks to this post: Determine the requested Controller in - ApplicationController

Here is how I ended up doing it (application.html.erb):

<%= render :partial => 'common/content_container', :locals => { :controller => params[:controller] } %>

content_container partial:

<% case controller
    when "sessions", "passwords"
        container_div_grid_number = "6"
        container_div_push_number = "5"
    else
        container_div_grid_number = "10"
        container_div_push_number = "3"
    end 
%>

<div class="grid_<%= container_div_grid_number %> push_<%= container_div_push_number %> ">
    <div class="top_<%= container_div_grid_number %>"></div>
    <div class="middle_<%= container_div_grid_number %>">
        <%= yield %>
    </div>
    <div class="bottom_<%= container_div_grid_number %>"></div>
</div>
Sign up to request clarification or add additional context in comments.

2 Comments

just for "good form", you might want to try moving that stuff to a helper so it isn't in the controller. In the views, there is an attribute called controller that makes the current controller instance available to you so you can check which controller you are using.
Thanks for the tip! I actually need to modify my code above cause I changed the way I set the classes because I noticed that in the original markup some of the numbers (with in the main div) changed...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.