Rails add text to class in a content_tag_for :li

I have a content tag that is creating jquery sortable output. Some items I don't want sortable, so I've added the following to the jquery:

    cancel: ".ui-state-disabled"

So, now I need to put "ui-state-disabled" into the li class.

Currently the code creating the li is this:

               <% wostatus.workorders.each do |workorder| %>
                <%= content_tag_for(:li, workorder) do %>
                    <div class="<%= workorder.type.maximo_no %> <%= workorder.priority %> ">
                      <a href="<%= workorder_path(workorder) %>">
                        <strong><%= workorder.wonum %></strong>
                        <%= workorder.description %>
                <% end %>
            <% end %>

The results in HTML are:

<li class="workorder" id="workorder_36">
    <div class="  ">
       <a href="/workorders/36">
                        Added some text again

In the browser, if I edit the li class to include "ui-state-disabled" it works the way I want.

Now, how can I insert the "ui-state-disabled" into the li status if the workorder.wostatus.id = 232 ??

Thanks for your help!!


Make a helper:

def disabled_workorder_li(workorder)
  {:class => "ui-state-disabled"} if workorder.id == 232

Then in the view:

<%= content_tag_for(:li, workorder, disabled_workorder_li(workorder) %>

Here's what it would look like if you skipped the helper and tried to do it all in the view:

<%= content_tag_for(:li, workorder, 
(workorder.id == 232) ? {:class => "ui_state_disabled"} : nil %>

That looks terrible. Putting it into a helper will also make it easier to test.

Need Your Help

GCD of two numbers in MIPS- recursive

recursion mips32

I am trying to find the GCD of two numbers with recursion.

API Server returns a 404 Error

mysql angularjs node.js twitter-bootstrap loopbackjs

I have created an AngularJS webapp that uses node, loopback, ui-router, and bootstrap.