RailsCasts Pro episodes are now free!

Learn more or hide this

Vu Nguyen's Profile

GitHub User: vnguyen13

Site: http://www.cs2n.org

Comments by Vu Nguyen

Avatar

I got it to work with tables by using this structure:

ruby
%table#sortable_table
  %thead
    %tr
      %th 
      %th Title
      %th Description
      %th Order
  %tbody{"data-update-url" => sort_featured_items_url}
    - @featured_items.each do |featured_item|
      =content_tag_for :tr, featured_item do
        %td
          = image_tag "shared/drag_handle.png", :alt => "Drag", :class => "handle"
        %td= featured_item.title
        %td= featured_item.description
        %td= featured_item.order

So basically you wrap your headers into a %thead tag and your other rows with a %tbody tag.

ruby
The JS then looks like this:
$("#sortable_table tbody").sortable({
        axis:'y',
        handle: '.handle',
        update: function(){
          $.post($(this).data('update-url'), $(this).sortable('serialize'));
        }
});
  });
Avatar

Nevermind, the thread above that started by "Coda" answered this.

Avatar

Hey I'm using the same code to dynamically add fields too! How did you handle the order position for multiple new fields?

Avatar

Nevermind, in my case it was:

ruby
resources :featured_items do
  collection do
    post "sort"
  end
end
Avatar

Thanks for the update. Can you show me what the routes look like with ruby 1.8.7? I can't seem to get mine working.

Avatar

Is there a way to do this when you have nested forms (associations)? As in, we have a @license object, and every @license has @progress_point. Well, the form for licenses looks like this:

ruby
= form_for @license, :url => path do |f|
  .field
    = f.label :name
    = f.text_field :name
  .field
    = f.label :active
    = f.check_box :active
  .field
    = f.label :data
    = f.text_area :data

  %table{:cellpadding => "10"}
    =f.fields_for :progress_points do |builder|
      = render "progress_point_fields", :f => builder


  = link_to_add_fields "Add Sequence", f, :progress_points

The partial "progress_point_fields" has:

ruby
%tr.dynamic_field
  %td
    .field
      = f.label :assessment_id
      = f.text_field :assessment_id
  %td
    .field
      = f.label :milestone_id
      = f.text_field :milestone_id
  %td
    .field
      = f.label :sequence
      = f.text_field :sequence

The problem is that :progress_points isn't an @object so I can't exactly get the ID (or at least I'm not aware of any way of getting it).

Any ideas? Thanks in advance

Avatar

Thanks. This plugin still isn't working for me so I guess that wasn't the issue.

Avatar

How do you create the following div in HAML?

< div data-pjax-container >

We're trying to use this plugin but it's not working and I have a feeling it's because we aren't converting that tag to HAML correctly. Anyone using HAML with this?