Setting parameters in link from javascript


I need to do an Ajax call to populate a span-tag with some text from
the server-side. I’m using ‘link_to_remote’ but I need to fetch one of
the parameters in the call from a form field.

Initially I tried something like:

<%= link_to_remote ‘…’, :url => {:action => ‘some_action’, :id => ‘$
(some_form_field).value;’}, :update => ‘target_span’ %>

This will obviously not work.

But - is there an easy way to do this using the Rails helpers? I
suppose it would be possibly by writing some custom Javascript - but
I’m trying to avoid that.

Best Regards //Anders

I’ll go ahead and answer my own question :slight_smile:

I managed to solve my specific problem by using the ‘submit’

<%= link_to_remote ‘…’, :url => {:action => ‘some_action’}, :update
=> ‘target_span’, :submit => ‘id_of_container_holding_the_input_form’

See where
the ‘submit’ parameter is described.


That’s exactly what I was looking for!

I couldn’t find the description on the Could you
(or anyone else) point me to a website where the usage of
link_to_remote’s :submit-parameter is described? The rails API-docs
arent very substantial regarding this…

My main-question is: How do I fetch the submitted parameter in the
controller method? Using params[:submit]?

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs