我一直在尝试构建一个搜索表单,允许用户通过选择多个复选框来选择下拉列表中的内容。当我提交表单,值越来越阵列中的在年底通过一个空值,当我检查日志查询看起来像这样简单表单多选复选框
UPDATE `searches` SET `ethnicity` = '---\n- Pacific Islander\n- White\n- Other\n- \'\'\n', `updated_at` = '2014-04-21 18:24:03' WHERE `searches`.`id` = 1
我不明白为什么我有额外的问题每个表单值周围的字符。我使用的简单的形式和我的形式看起来像这样
<%= simple_form_for(:search, :url => {:controller => 'searches', :action => 'update', :slug => session[:username]}) do |f| %>
<%= f.error_notification %>
<%= f.input :ethnicity, :label => "Ethnicity", :collection => ["Asian","Black", "Hispanic/Latino", "Indian", "Middle Eastern", "Native American", "Pacific Islander", "White", "Other"], :include_blank => "Anything", wrapper_html: { class: 'form-group' }, :as => :check_boxes, :input_html => {:name => "search[ethnicity][]", :multiple => true}, include_hidden: false %>
<% end %>
我的搜索控制器允许阵列从我的理解,因为即时通讯使用Rails 4,进出口使用强大的参数
def search_params
params.require(:search).permit(:id, :user_id, :ethnicity => []) if params[:search]
end
我只是张贴节的代码不工作,因为我的表单有其他领域,如性别,身高,年龄等,但这些都工作正常。当我使用复选框时,我只有问题。单选按钮和选择字段的工作完美。
这里是一个完整的搜索日志提交
Parameters: {"utf8"=>"✓", "authenticity_token"=>"WMR/U8ztPOb+Y8vGoAcP2Le5k8T5ZC02r0uoVdJMuSg=", "search"=>{"gender"=>"Female", "interested_in"=>"Men", "min_age"=>"22",
"max_age"=>"44", "ethnicity"=>["Pacific Islander", "White", "Other", ""],
"education"=>"", "income"=>"", "religion"=>"", "body_type"=>"", "min_height"=>"", "max_height"=>"", "smoke"=>"", "drink"=>"", "drugs"=>"", "exercise"=>"", "have_children"=>"",
"want_children"=>"", "pets"=>""}, "commit"=>"Search", "slug"=>"wahidp"}
Geokit is using the domain: localhost
User Load (0.5ms) SELECT `users`.* FROM `users` WHERE `users`.`id` = 1 LIMIT 1
Search Load (0.3ms) SELECT `searches`.* FROM `searches` WHERE `searches`.`user_id` = 1 LIMIT 1
(0.1ms) BEGIN
SQL (0.4ms) UPDATE `searches` SET `ethnicity` = '---\n- Pacific Islander\n- White\n-
Other\n- \'\'\n', `updated_at` = '2014-04-21 18:24:03' WHERE `searches`.`id` = 1
林完全是可能的东西建设的出路我联赛的初学者,但我已经深入研究这一问题,并需要更多帮助的时候。任何人都可以解释为什么这不工作,我需要做什么?谢谢!
我试图消除:include_blank => “任何”,但我接收到相同的日志输出
Processing by SearchesController#update as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"WMR/U8ztPOb+Y8vGoAcP2Le5k8T5ZC02r0uoVdJMuSg=", "search"=>{"gender"=>"Female", "interested_in"=>"Men", "min_age"=>"22", "max_age"=>"44", "ethnicity"=>["Other", ""], "education"=>"", "income"=>"", "religion"=>"", "body_type"=>"", "min_height"=>"", "max_height"=>"", "smoke"=>"", "drink"=>"", "drugs"=>"", "exercise"=>"", "have_children"=>"", "want_children"=>"", "pets"=>""}, "commit"=>"Search", "slug"=>"wahidp"}
Geokit is using the domain: localhost
User Load (0.6ms) SELECT `users`.* FROM `users` WHERE `users`.`id` = 1 LIMIT 1
Search Load (0.4ms) SELECT `searches`.* FROM `searches` WHERE `searches`.`user_id` = 1 LIMIT 1
(0.1ms) BEGIN
SQL (0.3ms) UPDATE `searches` SET `ethnicity` = '---\n- Other\n- \'\'\n', `updated_at` = '2014-04-21 21:24:55' WHERE `searches`.`id` = 1
我删除了:include_blank =>“Anything”选项,但仍然没有运气。 – wahidp
您可以使用搜索时生成的新服务器日志来更新问题。 –
好的,我做到了。日志产生了相同的输出。 – wahidp