views:

515

answers:

0

I'm generating jQuery UI slider elements in a Rails helper:

def add_link(form_builder, method)
  link_to_function 'Add' do |page|
    page << "$(\"div#range\"+new_id+\"\").slider({
      range: true,
      min: 1,
      max: 7,
      values: [parseInt($(\"#lecture_events_attributes_\"+new_id+\"_from_block\").val()),   parseInt($(\"#lecture_events_attributes_\"+new_id+\"_to_block\").val())],
      slide: function(event, ui) {
        $(\"#lecture_events_attributes_\"+new_id+\"_from_block\").val(ui.values[0]);
        $(\"#lecture_events_attributes_\"+new_id+\"_to_block\").val(ui.values[1]);
      }
    });"
  end
end

Basically, it just adds the slider to a div and runs the slider-js code.

If I change one of the generated slider values and generate a new one, all values are reseted to the default values, which is very annoying.

What's wrong here? Id's are correct, rechecked everything. I'm fiddling around since hours.

Thanks!