Coder Social home page Coder Social logo

Comments (7)

tubaxenor avatar tubaxenor commented on May 20, 2024

端看你希望怎麼讓rails幫你處理上傳的request,如果是一個form裡頭多個照片檔案(一個POST request),那你就必須設 accepts_nested_attributes_for

另外一種做法是多個request,即是每上傳一個照片就產生一個Photo record,Form submit的時候再把這些Photo一個個加進blog post.

若有速度考量,第二種方式可以async處理,第一種比較沒有辦法,若request包含太多大容量檔案容易花很多時間甚至是timeout。

from ama.

afgnsu avatar afgnsu commented on May 20, 2024

其實是沒使用過這種方式,才會上來問問大家的意思,如果用Rails101s的巢狀路由的方法,好像變得綁手綁腳的,主要我還要用來新增或修改多張照片。

from ama.

hechien avatar hechien commented on May 20, 2024

@afgnsu check nested_form.

accepts_nested_attributes_for 對於新增子元素來說是一個非常方便的方式,它會幫你在儲存主物件的時候連同子物件一起存進去

所以當你有一篇文章,而該篇文章有多圖片的時候,用這種方式最為方便

from ama.

afgnsu avatar afgnsu commented on May 20, 2024

新增很容易,但是想請問一下要如何再次新增/編輯?因為看起來路由是沒有關聯 :P

假設我要再次新增,我該如何讓新增的圖片同屬於原本的部落格文章?用 hidden_field 欄位嗎?

from ama.

hechien avatar hechien commented on May 20, 2024

@afgnsu 可以參考 https://gist.github.com/iqbalhasnan/24905170bdfd182cd631

from ama.

afgnsu avatar afgnsu commented on May 20, 2024

謝謝,我馬上試試 ^_^

from ama.

afgnsu avatar afgnsu commented on May 20, 2024

最後用 cocoon 套件排除 XD

from ama.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.