views:

64

answers:

1

Hello! I'm making "user settings form", and stuck with HAML:

= form_tag('/')
  - [1,2,3].each do |i|
    =  check_box_tag "accept#{i}"
  = submit_tag

This results in "syntax error, unexpected kENSURE, expecting $end".

The working variant is = form_tag('/') - [1,2,3].each do |i| = check_box_tag "accept#{i}" = submit_tag

Results in

 <input id="accept1" name="accept1" type="checkbox" value="1" />
    <input name="commit" type="submit" value="Save changes" />
    <input id="accept2" name="accept2" type="checkbox" value="1" />
    <input name="commit" type="submit" value="Save changes" />
    <input id="accept3" name="accept3" type="checkbox" value="1" />
    <input name="commit" type="submit" value="Save changes" />
    <form action="/" method="post"><div style="margin:0;padding:0;display:inline"><input name="authenticity_token" type="hidden" value="tuniieYp9hgvGBMaYDjK2l3Mgjpxo9F1LPzqEF4ykHg=" /></div>

Wrong: controls outside form tag, 3 times submit button.

Any ideas on fixing would be appreciated. Thank you!

+1  A: 

You should be passing a block to form_tag. I think you want:

- form_tag('/') do
  - [1, 2, 3].each do |i|
    = check_box_tag "accept#{i}"
  = submit_tag
nirvdrum