사용자가 책을 만들 때 책 ID와 동일한 이름으로 이미지를 업로드하는 레일 응용 프로그램이 있습니다 (assets/books_icon
). 그것은 개발 mode.Then에서 작동레일 프로덕션 환경에서 파일 업로드 후 파일 경로가 업데이트되지 않습니다.
upload_icon(params[:book][:image_upload])
# upload_image when create/update book
def upload_icon(uploaded_io)
photo_directory = "app/assets/images/"
# only when user upload the iphoto
if uploaded_io.present?
# upload to the exact location with category_id
extension = File.extname(uploaded_io.original_filename)
photo_location = 'books_image/'+ @book.id.to_s + extension
# open in binary mode
photo_full_location = photo_directory + photo_location
File.open(photo_full_location, 'wb') do |file|
file.write(uploaded_io.read)
end
# only have to state which is the directory,
# image_tag will use assets piepline which will add 'assets/images/' as prefix in src
@book.update_attribute(:image_url, photo_location)
end
end
, 나는 데이터베이스로 MySQL과 맥 아파치 서버에서 승객과 레일 응용 프로그램을 배포하고 난 개발의 구성 파일에 config.assets.compile = true
을 변경했습니다.
생산 모드에서 새 책을 만들 수 있으며 이미지를 assets/books_icon
에 업로드 할 수 있습니다. 그러나 방금 업로드 한 이미지의 파일 경로는 update
이 아닙니다.
예를 들어, id가 2 인 새 책을 만들고 assets/books_icon
에 2.jpg가 있습니다. 하지만 레일 응용 프로그램은 http://localhost/assets/images/books_icon/2.jpg
가 누락되었다고 말합니다. 나는 아파치 서버를 다시 시작할 때
그러나, 나는 http://localhost/assets/images/books_icon/2.jpg
caching
이러한 유형의 문제를 해결하기 위해 어떤 해결책이 거기에서 사진을 볼 수 있습니다 ??
공개 앱이 아닌 앱/저작물에 저장하도록 특정 요구 사항이 있나요? –
아무런 요구 사항이 없습니다 :) 그것은 내 숙제를위한 제 디자인입니다. – code4j