Rails clone copy or duplicate

后端 未结 4 1544
孤独总比滥情好
孤独总比滥情好 2020-12-31 10:19

I have a nested form and once I save, I want to be able to click a link on the show page to copy or clone that form and open a new one. From there I should be able to make e

4条回答
  •  离开以前
    2020-12-31 11:02

    If you want to copy an activeRecord object you can use its attributes to create new one like

    you can have an action in your controller which can be called on link,

    def  create_from_existing
     @existing_post = Post.find(params[:id])
     #create new object with attributes of existing record 
     @post = Post.new(@existing_post.attributes) 
     render "your_post_form"
    end
    

提交回复
热议问题