2010-02-24 7 views
0

회사에 대한 일반적인 특성을 포함하고 있지만 회사 로고가 첨부 된 모델 (클라이언트)을 설정하려고합니다. 가능한 경우 레일의이 측면을 파악하기 때문에 플러그인을 사용하기를 꺼립니다.모델에 연결된 이미지를 편집하는 레일

클라이언트 모델과 이미지 모델을 만들었으며 새 클라이언트 (스캐 폴드 코드)를 만들고 첨부 된 이미지를 확인 (has_one :imagebelongs_to :client 사용) 할 수 있습니다.

나는 (애자 레일 3 에디션에서 바로 촬영) 다음 코드

class Client < ActiveRecord::Base 
    has_one :image 

    def uploaded_image=(image_file) 
    self.image = Image.new 
    self.image.name = base_part_of(image_file.original_filename) 
    self.image.content_type = image_file.content_type 
    self.image.data = image_file.read 
    end 

    def base_part_of(filename) 
    File.basename(filename).gsub(/^\w_-/,'') 
    end 

end 

을 사용하는 경우 편집 클라이언트 객체가 있지만, 새로운 파일이 업로드되어 있지만 변경 사항이 DB에 반영되지 않습니다. @client.image에서 update-attributes를 명시 적으로 호출해야합니까? 다음 순간 내 컨트롤러 업데이트 방법은 다음과 같습니다 어떤 조언에 미리

def update 
    @client = Client.find(params[:id]) 

    respond_to do |format| 
    if @client.update_attributes(params[:client]) 
     flash[:notice] = 'Client was successfully updated.' 
     format.html { redirect_to(@client) } 
     format.xml { head :ok } 
    else 
     format.html { render :action => "edit" } 
     format.xml { render :xml => @client.errors, :status => :unprocessable_entity } 
    end 
    end 
end 

감사합니다, 멍청한 놈 질문

+0

새 작업 및 편집 작업에 대한보기를 표시하십시오. – klew

답변

2

에 대한 사과는 내가 강하게 대신 Paperclip를 사용하는 것이 좋습니다. 그냥 작동합니다.

+0

아니면 최소한 Paperclip 소스를 살펴보십시오. –

+0

팁을 주셔서 감사합니다. 별도의 업데이트 작업을 사용하고 있지만 자습서에서 본 일부 클립 코드만큼 깨끗하지는 않습니다. 네, Paperclip 소스도 보도록하겠습니다. 감사합니다. Toby – gcahill

관련 문제