$30 off During Our Annual Pro Sale. View Details »

[教育訓練] Rails Form Basic

HeChien Hsu
September 04, 2012

[教育訓練] Rails Form Basic

HeChien Hsu

September 04, 2012
Tweet

More Decks by HeChien Hsu

Other Decks in Technology

Transcript

  1. Rails Form
    徐赫謙

    View Slide

  2. Rails Form
    Basic

    View Slide

  3. Built-in
    • form_tag
    • form_for

    View Slide

  4. form_tag
    • 不主動對應Model
    • 適⽤用於不需要與Model直接互動的表單

    View Slide

  5. form_for
    • 與Model有直接的關係
    • 需要帶⼊入Resource
    • 欄位名稱⼀一定要是能存取的屬性

    View Slide

  6. field helpers (tag)
    • text_field_tag
    • text_area_tag
    • hidden_field_tag
    • label_tag
    • select_tag
    • submit_tag
    • check_box_tag
    • radio_button_tag
    • field_set_tag
    • password_field_t
    ag
    • ... more

    View Slide

  7. field helpers (for)
    • text_field
    • text_area
    • hidden_field
    • label
    • select
    • submit
    • check_box
    • radio_button
    • fields_for
    • password_field
    • file_field
    • ... more

    View Slide

  8. Example
    • form_for: https://gist.github.com/3507380#file_form_for.html.erb
    • form_tag: https://gist.github.com/3507380#file_form_tag.html.erb

    View Slide

  9. Nested Form
    可以輕易的建⽴立嵌套Model的Records

    View Slide

  10. Nested Form
    https://gist.github.com/3507380#file_survey.rb

    View Slide

  11. Built-in

    View Slide

  12. Rubygem

    View Slide

  13. Simple Form

    View Slide

  14. https://gist.github.com/3507380#file_simple_new.html.erb

    View Slide

  15. Simple Form

    View Slide

  16. Rubygem

    View Slide