Topic: Rails 3.2 option chooser in form

He,im new to Rails and i have a big problem with an option chooser. The user can choose per checkbox, if he wants to use a selectbox or a text_field. The jquerycode does his job by showing or hidding the div. But when i submit the form, :task_name gets always the value of the task_new div but never the one of the task_use. What im doing wrong?Is there a way for hidding/showing the div per railsfunction?
Maybe i set up some tmp variables and give :task_name the value?! How can this be done?

Update:
I tryed the trick with the tmp_variables. The get an value but now i stuck, how to set the value of the tmp_variable to :task_name ....
<% :task_name = @tmp_variable%> doest work????

Heres the code:
new.html.erb
.......
Create new Task :
<input type="checkbox" value="false" name="check" id="check" checked="false" />
</div>

<div class="task_use" id="task_use" style="display:block;">
<%= f.fields_for :task do |t|%> 
<%= t.select :task_name, Task.all.collect {|n|[n.task_name]}%>
<%end%>
</div>
<div class="task_new" id="task_new" style="display:none;">
<%= f.fields_for :task do |t|%>
<%= t.label :task_name %><br />
<%= t.text_field :task_name %>
<%end%>
</div>
<div class="actions">
<%= f.submit %>
</div>
<% end %>

<script>
$(document).ready(function() {
$("#check").change(function () {
if ($('#check').checked == false) {
} else {
$('#task_new').toggle();
$('#task_use').toggle();
}
});
});
</script>

Thx for your support

Last edited by mwiron (2012-09-14 02:08:49)