Rails 複数選択check_box_tag 例

"undefined method 'merge'などのエラーについて

解決例:

= f.check_box(:kindergarten, {}, true, false)
注意!

    = f.check_box ( :high, { :multiple => true }, true, false)のようにboxのあとスペースを入れるとエラー! 

syntax error, unexpected ',', expecting ')' ...(( f.check_box ( :kindergarten, { :multiple => true }, true,...

などとなります。

 

例;

- @categories.each_with_index do |category,i|
= check_box_tag "category#{i+1}", category.id
= category.name

 間違え:

/ = check_box_tag "question[category_ids]", category.id, @question.categories.include?(category)
/ = category.name

 

/ = check_box "question[category_ids]", category.id, @question.categories.include?(category)
/ = category.name

 

/ =f.check_box :category1, {}, true, false
/ 家庭学習

 

stackoverflow.com

You are getting mixed up between two ways of generating a check box I think.

The form builder version, f.check_box, you are using expects a hash as the second parameter. You'd need to call f.check_box(:is_female, {}, true) for a value of true.

check_box_tag on the other hand does expect a value as the second parameter. You could use check_box_tag(:is_female, true) instead.

However, as @Santosh points out in the comments, you'd probably be better off having a pair of radio buttons if you want the object to be either male or female.

shareimprove this answer
 
    
Thanks! I will let you know if your solution works. –  user3435032 Jun 3 '14 at 15:18

ーーーーーー他のリンク

qiita.com