Attaching an onClick event to a Rails link_to_function

How do I associate an onclick event with link_to_functionan element on the page that is updated (using partial) when I click on the event?

When the user clicks on the generated link, I would like to update the part containing the code in order to update i.

 def add_step_link(form_builder)
    logger.info 'ADD_STEP_LINK'
    link_to_function 'add a step' do |page|
      form_builder.fields_for :steps, Step.new, :child_index => 'NEW_RECORD' do |f|
        logger.info 'inserted js'
        html = render(:partial => 'step', :locals => { :step_form => f, :i=>@i+=1})
        page << "$('steps').insert({ bottom: '#{escape_javascript(html)}'.replace(/NEW_RECORD/g, new Date().getTime()) });"
      end
    end
  end 

I have a partial in a larger form that contains only:

<%= add_step_link(technique_form) %>

I am trying to track the number of steps in a technique. In the form that I create, users can add new steps to the set of instructions. Right now, I have default fields for steps 1-7. Adding one step, you get step 8. The problem is that the subsequent steps are also numbered "8".

" " http://railsforum.com/viewtopic.php?id=28447 .

+5
2

, , , .

link_to_function link_to_remote. javascript, , , , rjs, , , , ( ) .

, , ( link_to_remote, remote_form_for) . 3/4 http://media.rubyonrails.org/video/rails_blog_2.mov

link_to_remote : http://api.rubyonrails.org/classes/ActionView/Helpers/PrototypeHelper.html

+5

link_to_remote, RichH. , , @i. URL link_to_remote . - , .

0

All Articles