회사에 대한 일반적인 특성을 포함하고 있지만 회사 로고가 첨부 된 모델 (클라이언트)을 설정하려고합니다. 가능한 경우 레일의이 측면을 파악하기 때문에 플러그인을 사용하기를 꺼립니다.모델에 연결된 이미지를 편집하는 레일
클라이언트 모델과 이미지 모델을 만들었으며 새 클라이언트 (스캐 폴드 코드)를 만들고 첨부 된 이미지를 확인 (has_one :image
및 belongs_to :client
사용) 할 수 있습니다.
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
감사합니다, 멍청한 놈 질문
새 작업 및 편집 작업에 대한보기를 표시하십시오. – klew