开发者

Fields added with Jquery in Rails 3 are not visible in controller using params

I'm using rails 3 and Jquery to dynamically add field in a form_tag using a button "Add packages". I'm using the following code in Jquery:

  var counter = 1;
  $('#but').click(function()
  {
        var s = '<%= escape_javascript(render(:partial => "form2")) %>';
        var p = $(s);
        $('#packagename', p).attr("name","packagename" + counter);
        $('#type',p).attr("name","type" + counter);
        $('#price', p).attr("name", "price" + counter);
        $('#pricetype', p).attr("name", "pricetype" + counter);
        $('#currency', p).attr("name", "currency" + counter);
        $('.fac', p).each(function(){
          $(this).attr("name", $(this).attr("name") + counter);
        });
        $('.pack').append(p);
        counter ++;
  }

in order to rename the "name" attribute so i can pass the values of the fields to the controller using params. This is my partial "form2"

<div class="span-16" style="padding-bottom:10px;" id="package">
  <%= label_tag "PACKAGE: " %> <br /> <br/>
 <%= label_tag "Name*:" %> <br />
 <%= text_field_tag :packagename %>
<br />
<%=label_tag "Type:*"%> <br />
 <% ["Private office", "Private room", "Shared desk"].each do |type| %>
  <%= radio_button_tag  "type", type, false, :class => 'option_types', :id => 'type' %>
  <%= label_tag type, type %>
<% end %>
 <%= render 'price' %>
<%= label_tag "Available fa开发者_开发问答cilities and amenities:" %><br />
  <% ["Printer", "Wi-Fi"].each do |fac| %>
    <%= check_box_tag  fac, fac, false, :class => 'fac' %>
    <%= label_tag fac, fac %>

  <% end %>

</div>

However, the parameters for the fields added with jquery are not showing in the controller or on the server's section for params. The html source can be found here : http://pastebin.com/AszhDL8Y Any ideas?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜