Depending on the selection in a selection box I need to render a
partial. I want to do this without calling the server. I think I need
to use link_to_function. The problem is that I dont see how to
implement this for a selection box. I also what to trigger the partial
rendering immediately after the user made a selection in the box (and
thus not clicking on a button)
Whatever you wanted to put in the link_to_function, put in the
onchange of the select. Note that since you don't want to make the
round trip to the server to render the partial, or update a div with
the contents of the partial, whatever you want to display as a result
of the user selecting something in the select box, needs to be already
on the page. You'll just show/hide divs depending on the user
selection.
In your controller you could then do something like:
def some_action
# do stuff
render :update do |page|
page['update_me'].replace_html :partial => param[:div_id]
page[params[:div_id].show
end
end
Instead of the render :update block, you can have a respond_to |
format> block and put a format.js {} in there, create an rjs template
with the name of the action, and paste the code inside the
render :update block in it.