0

I would appreciate it if someone could help me with the following issue.

I have in my form the following code:

Type:  <%= f.select(:SUB_TYPE, [
            ['type A', 'type A'],
            ['type B', 'type B'],
            ['Type C', 'type C']
            ],{ :prompt => "Please select"}
            ) %>



  <% f.fields_for :author do |builder| %>
  <%= render :partial=>'sub/formAuthor', :locals => {:f => builder, :sub_type_selected => value_of_selected_type} %>
  <% end %>

I need to pass the type selected by the user to the partial 'formAuthor' and I would like to do so by passing the selected type value via the variable ':sub_type_selected'.

My question is how do I pass the value of the selected type to that partial.

Any suggestion is most appreciated.

4

1 回答 1

0

You cannot do that. The selected value is not known when the partial is built. The partial is processed before the user even sees the drop down. You should either hide the partial block, and load it after the user makes a selection, or load for all values and use tabs or similar mechanism to hide/ show. Basically, you will have to manage it with javascript or ajax.

于 2012-05-31T19:02:05.530 回答