开发者

HAML: form_tag dilemma (indentation?)

开发者 https://www.devze.com 2023-01-11 08:01 出处:网络
I\'m making \"user settings form\", and stuck with HAML: = form_tag(\'/\') - [1,2,3].each do |i| =check_box_tag \"accept#{i}\"

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="tuniieYp开发者_Python百科9hgvGBMaYDjK2l3Mgjpxo9F1LPzqEF4ykHg=" /></div>

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

Any ideas on fixing would be appreciated. Thank you!


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

Rails 2.x:

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

Rails 3+:

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

精彩评论

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