클립 클립을 통해 아바타를 사용하고 싶습니다. 튜토리얼에서 나는이 코드를 변경하고 작업 Gravatar에클립 클립으로 이미지 크기를 조정하는 방법
messages_helper.rb에게
def recipients_options(chosen_recipient = nil)
s = ''
User.all.each do |user|
s << "<option value='#{user.id}'
data-img-src='#{gravatar_image_url(user.email, size: 50)}'
#{'selected' if user == chosen_recipient}>
#{user.name}</option>"
end
s.html_safe
end
를 사용합니다.
module MessagesHelper
def recipients_options(chosen_recipient = nil)
s = ''
User.all.each do |user|
s << "<option value='#{user.id}' data-img-src='#{user.avatar.url(:thumb)}'
#{'selected' if user == chosen_recipient}>#{user.username}</option>"
end
s.html_safe
end
end
new.html.erb
<div class="form-group">
<%= label_tag 'recipients', 'Choose recipients' %>
<%= select_tag 'recipients', recipients_options(@chosen_recipient), multiple: true, class: 'form-control chosen-it ' %>
</div>
user.rb
has_attached_file :avatar, :styles => { :medium => "150x150>", :thumb => "30x30#" }, default_url: "https://s3.amazonaws.com/myinstick/logo/instagram-icon.png"
validates_attachment_content_type :avatar, :content_type => /\Aimage\/.*\Z/
을하지만! 사용자가 아바타를 갖고 있지 않으면 이미지 클립 클립을 사용합니다. 그리고 그것은 스케일링을하지 않습니다 그리고 그것은 크게 보입니다. 스타일이나 크기를 설정하는 방법. 모델의
그냥에 대한 선택 CSS를 제대로 찾을 작동 이 이미지를 만들고 다음과 같은 CSS를 만드십시오 :'.my-big-img-class {max-width : 50px}' – Victor