Q: Calling javascript function from button_tag? I have next file with jquery function:
assets/ javascripts/poll_items.js
$(document).ready(function(){
    $('.up_id').on('click', function() {
    $(this).closest('.poll_row').insertAfter($(this).closest('.poll_row').next());
  });
  $('.down_id').on('click', function() {
    $(this).closest('.poll_row').insertBefore($(this).closest('.poll_row').prev());
  });
});

when i click `= button_tag 'up', type: 'button', value: 'up', input_html: {class: 'up_id'}'   nothing happens. How me correct call code from file javascript?
full code:  
polls/new.html.haml
%h1= title "Новый опрос"
= simple_form_for @poll do |f|
  = f.error_messages header_message: nil
  = f.input :question, disabled: !@poll.editable?(current_user), input_html: { class: 'input-block-level' }
  = f.input :results_hidden, as: :boolean, inline_label: 'Скрыть результаты до окончания опроса', label: false
  = f.input :from_date, as: :datetime, input_html: { class: 'poll_date' }
  = f.input :to_date, as: :datetime, input_html: { class: 'poll_date' }
  %h3#poll-items Варианты ответа (не больше пяти)
  .item_index  
    = f.simple_fields_for :poll_items do |poll|
      = render 'poll_item_fields', f: poll
    = link_to_add_association 'Добавить еще вариант', f, :poll_items
    .form-actions
      = f.button :submit, 'Опубликовать опрос', class: 'btn-bg'
      %p 
        Вернуться к посту:
        = link_to @owner

poll_fields.html.haml
%h3#poll-items Варианты ответа (не больше пяти)
.item_index  
  = f.fields_for :poll_items do |poll|
    = render "poll_item_fields", f: poll
  .links
    = link_to_add_association 'Добавить еще вариант', f, :poll_items, render_options: {class: 'links'}

poll_item_fields.html.haml
.poll_row
  .poll_item
    = f.input :answer, input_html: { class: 'ctrlenter expanding' }, label: false, placeholder: 'Введите вариант ответа'
    = button_tag 'up', type: 'button', class: 'up_id', value: 'up'
    = button_tag 'down', type: 'button', class: 'down_id', value: 'down'
    = link_to_remove_association "удалить", f, { wrapper_class: 'poll_item' } 


A: I am suspecting that the DOM is getting build dynamically so try changing your JS code as follows:
$(document).ready(function(){
  $(document).on('click', '.up_id', function() {
    $(this).closest('.poll_row').insertAfter($(this).closest('.poll_row').next());
  });
  $(document).on('click','.down_id', function() {
    $(this).closest('.poll_row').insertBefore($(this).closest('.poll_row').prev());
  });
});

Here we are using event delegation technique to propagate the click event to required DOM element which may be present in DOM.

A: SOLUTION:
I added in application.js.coffee #=require poll_items.js and everything works
