yer*_*syl 2 html javascript checkbox ruby-on-rails
我想根据选择值生成一些复选框。所以我有选择标签:
<%= f.collection_select :type, RequestType.order(:typeName), :id, :typeName,
{include_blank:true }, {:class => "types"} %>Run Code Online (Sandbox Code Playgroud)
当 select 的值更改时,我想生成一些复选框,为此我有 div:
<div id="sub_types"> </div>Run Code Online (Sandbox Code Playgroud)
def show_sub_types
@rtype = params[:id];
@stypes = RequestSubType.where("request_type_id=?", @rtype).all
respond_to do |format|
format.js
format.html
end
endRun Code Online (Sandbox Code Playgroud)
$("#sub_types").html("");
$("#sub_types").append("<%= j render 'show_sub_types', stypes: @stypes %>");Run Code Online (Sandbox Code Playgroud)
<% stypes.each do |type| %>
<%= check_box_tag "subtype", type.id %>
<%= type.subTypeName %>
<br>
<% end %>Run Code Online (Sandbox Code Playgroud)
在我的部分我做这样的事情。此代码生成我的复选框。他们看起来像这样:
<input type="checkbox" name="subtype" id="subtype" value="1">Run Code Online (Sandbox Code Playgroud)
但现在我不知道如何用我的表单提交这些复选框值。我想在 db 中存储多个复选框值作为数组。
请试试这个
<% stypes.each do |type| %>
<%= check_box_tag 'stype_ids[]', type.id %>
<%= type.subTypeName %>
<br>
<% end %>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
200 次 |
| 最近记录: |