Rails—HTML樣式
阿新 • • 發佈:2018-12-26
複選框 check_box_tag
check_box_tag 'accept'
# => <input id="accept" name="accept" type="checkbox" value="1" />
check_box_tag 'rock', 'rock music'
# => <input id="rock" name="rock" type="checkbox" value="rock music" />
check_box_tag 'receive_email', 'yes', true
# => <input checked="checked" id="receive_email" name="receive_email" type="checkbox" value="yes" />
check_box_tag 'tos', 'yes', false, class: 'accept_tos'
# => <input class="accept_tos" id="tos" name="tos" type="checkbox" value="yes" />
check_box_tag 'eula', 'accepted', false, disabled: true
# => <input disabled="disabled" id="eula" name="eula" type="checkbox" value="accepted" />
通過 value的值可判斷check_box是否存在
文字框 text_field_tag
text_field_tag 'name'
# => <input id="name" name="name" type="text" />
text_field_tag 'query', 'Enter your search query here'
# => <input id="query" name="query" type="text" value="Enter your search query here" />
text_field_tag 'search', nil, placeholder: 'Enter search term... '
# => <input id="search" name="search" placeholder="Enter search term..." type="text" />
text_field_tag 'request', nil, class: 'special_input'
# => <input class="special_input" id="request" name="request" type="text" />
text_field_tag 'address', '', size: 75
# => <input id="address" name="address" size="75" type="text" value="" />
text_field_tag 'zip', nil, maxlength: 5
# => <input id="zip" maxlength="5" name="zip" type="text" />
text_field_tag 'payment_amount', '$0.00', disabled: true
# => <input disabled="disabled" id="payment_amount" name="payment_amount" type="text" value="$0.00" />
text_field_tag 'ip', '0.0.0.0', maxlength: 15, size: 20, class: "ip-input"
# => <input class="ip-input" id="ip" maxlength="15" name="ip" size="20" type="text" value="0.0.0.0" />
提交按鈕 submit_tag
submit_tag
# => <input name="commit" type="submit" value="Save changes" />
submit_tag "Edit this article"
# => <input name="commit" type="submit" value="Edit this article" />
submit_tag "Save edits", disabled: true
# => <input disabled="disabled" name="commit" type="submit" value="Save edits" />
submit_tag "Complete sale", data: { disable_with: "Please wait..." }
# => <input name="commit" data-disable-with="Please wait..." type="submit" value="Complete sale" />
submit_tag nil, class: "form_submit"
# => <input class="form_submit" name="commit" type="submit" />
submit_tag "Edit", class: "edit_button"
# => <input class="edit_button" name="commit" type="submit" value="Edit" />
submit_tag "Save", data: { confirm: "Are you sure?" }
# => <input name='commit' type='submit' value='Save' data-confirm="Are you sure?" />