2
Rails 애플리케이션에 이미지를 업로드하려고합니다. 그러나, 나는 그렇게 할 수 없다. 나는 레일에 비교적 익숙하지 않아 여기에 도움이 필요합니다.클립 클립을 사용하여 이미지 업로드 3
나는 "화상"모델이 여기에 표시 한 -
class Picture < ActiveRecord::Base
attr_accessible :photo, :tag
has_attached_file :photo, :styles => { :medium => "300x300>",
:large => "1000x1000>", :thumb => "100x100>" }
end
나는 "사진"컨트롤러가 여기에 표시해야 -
class PicturesController < ApplicationController
def new
@picture = Picture.new
end
def create
@picture = Picture.create(params[:picture])
if @picture.save
flash.now[:success] = "Image Uploaded"
redirect_to @picture
else
render 'new'
end
end
def index
end
def show
@picture = Picture.find(params[:id])
send_data @picture.photo, :type => 'image/png', :disposition => 'inline'
end
def imageshow
end
end
마지막으로,이 내 "새"와 "쇼"입니다 조회수 :
"new.html.erb"
<h1>Upload an Image</h1>
<div>
<%= form_for(@picture, :html => {:multipart => true}) do |f| %>
<%= f.file_field :photo %>
<%= f.label :tag %>
<%= f.text_field :tag %>
<%= f.submit "Submit", class: "btn btn-large btn-primary" %>
<% end %>
</div>
"show.html.erb"나는 업로드 페이지에 도달 할 수 있어요
<h1>Displaying Uploaded Image</h1>
<div>
<%= image_tag @picture.photo.url %>
<%= image_tag @picture.photo.url(:large) %>
</div>
(즉, 그림 컨트롤러에서 new.html.erb).
"이 오류를 포함하고 있기 때문에 표시 할 수 없습니다"이
"이 이미지는"http://10.102.119.20:3000/pictures/12 : 나는 이미지를 업로드 할 때, 나는 다음과 같은 오류가 발생합니다 내 검색어 :
- 이미지는 서버에서 어디서 업로드됩니까?
- 수행해야 할 구성이 있습니까?
- 내 코드에 다른 문제가 있습니까?
미리 도움 주셔서 감사합니다 .. !!
제가 클립 클립을 마지막으로 사용했을 때 이미지가 'public' 디렉토리 – iGbanam
Yasky에 업로드되면 사실입니다. 나는 어떻게 든 기본적으로 이미지가/public 디렉토리에 업로드된다는 것을 알게되었습니다. 정확히 말하면,/root/rails_project/sample_app/public/system/pictures/photos .. 그러나 그림 컨트롤러의 show 메서드를 사용하여 이미지를 표시 할 수 없습니다. 위의 show 메서드에서 내가 무엇을 사용하고 있는지 알 수 있습니다. 어떤 아이디어? –