instance variable vs. symbol in ruby on rails (form_for)

前端 未结 2 1071
自闭症患者
自闭症患者 2020-11-27 06:29

i\'m new to ruby on rails and am working with version 2.3 on mac osx. i am trying to create the same functionality a scaffold creates, but on my own. i created a \"post\" co

2条回答
  •  无人及你
    2020-11-27 07:00

    if you use symbol :post it creates

    if you use the instance @post

    for @post = Post.new you will get

    
    

    for @post = Post.find(1) you will get

    
    
    

    if you have different forms for your new and your edit no big deal but more likey than not your new and your edit forms are going to be identical or close to it

    so if you use the instance variable @post you can put all the form code into _form and just call the partial and it will handle the rest based on if you pass in a new record or an existing record

提交回复
热议问题