내 해결책은 다음과 같습니다.
모델에 STYLES 상수를 정의하십시오.
응용 프로그램에서, 마지막으로, 새로운 Paperclip interpolation
설정/초기화/paperclip.rb
# returns value of the STYLES[:dimansion]
# Post::STYLES[:tiny] -> '20x20'
Paperclip.interpolates :dimension do |attachment, style|
key = style.to_sym
return Post::STYLES[key].gsub(/[^\d\w+]/, '') if Post::STYLES.has_key?(key)
'900x500' # or return default :original dimensions
end
를 만들고보다/모델/post.rb
class Post < ActiveRecord::Base
# ...
STYLES = {
large: '300x300#',
medium: '250x250#',
small: '100x100#',
thumb: '50x50#',
tiny: '20x20#'
}
has_attached_file :attachment, {
styles: STYLES,
default_url: '/assets/holder.js/:dimension',
path: # your path
url: # your url
}
# ...
end
당신의 조회수 :
,451,515,
<%= image_tag nil, { data: { src: 'holder.js/200x200' } } %>
또는
<%= tag :img, { src: '', data: { src: 'holder.js/200x200' } } %>
희망이 도움이됩니다.
추신. 더 나은 사용 holder_rails 보석
UPDATE : 두려워, 당신은
default_url: '/assets/holder.js/:dimension'
대신
default_url: 'holder.js/:dimension'
희망이 곧이 문제를 해결하기 위해
(오류 라우팅을 가지고)를 사용합니다.