Итак, я пытаюсь использовать свой MacBook Pro, который я использую, и использую его для разработки веб-сайта, который был сделан преимущественно на Ubuntu на действительно старом ноутбуке Lenovo.На моем Mac у меня высокая sierra, и я установил imagemagick с помощью homebrew, однако мои изображения в моем блоге на локальном сервере слишком непропорциональны и не масштабируются так, как им подсказывает minimagick, поэтому мой RSS-канал выглядит беспорядочно, дажехотя это выглядит совершенно нормально с тем же кодом на моем Linux.Какие-либо предложения?
Gemfile
gem 'carrierwave'
gem 'mini_magick'
gem 'fog'
image_uploader.rb
class ImageUploader < CarrierWave::Uploader::Base
include CarrierWave::MiniMagick
storage :fog
process resize_to_fit: [300,300]
version :medium do
# change the word 'fit' to 'fill'
process resize_to_fill: [400,400]
end
version :large do
process resize_to_fill: [1000,1000]
end
def store_dir
"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end
def extension_white_list
%w(jpg jpeg gif png)
end
end
модель:
class HomeBlog < ApplicationRecord
mount_uploader :image, ImageUploader
has_many :hashtaggings, dependent: :destroy
has_many :hashtags, through: :hashtaggings, dependent: :destroy
acts_as_votable
def next
self.class.where("id > ?", id).first
end
def previous
self.class.where("id < ?", id).last
end
def last
self.class.where("id = ?", id).last
end
def self.highest_voted
self.order("cached_votes_total DESC")
end
def all_hashes=(names)
self.hashtags = names.split(",").map do |name|
Hashtag.where(name: name.strip).first_or_create!
end
end
def all_hashes
self.hashtags.map(&:name).join(", ")
end
end
контроллер:
class HomeBlogsController < ApplicationController
before_action :authenticate_user!, only: [:upvote, :downvote]
before_action :set_home_blog, only: [:show, :upvote, :downvote]
# GET /home_blogs
# GET /home_blogs.json
def index
end
def rss_feed
@home_blogs = HomeBlog.order('created_at DESC').paginate(:page => params[:page], :per_page => 3)
@highest_voted = HomeBlog.highest_voted.first
end
# GET /home_blogs/1
# GET /home_blogs/1.json
def show
@home_blog = HomeBlog.find(params[:id])
@next_home_blog = @home_blog.next
@previous = @home_blog.previous
end
# GET /home_blogs/new
def new
@home_blog = HomeBlog.new
end
# GET /home_blogs/1/edit
def edit
end
# POST /home_blogs
# POST /home_blogs.json
def upvote
@home_blog.upvote_from current_user
redirect_to request.referrer
flash[:success] = "thanks for the vote"
end
def downvote
@home_blog.downvote_from current_user
redirect_to request.referrer
flash[:success] = "thanks for the vote"
end
# PATCH/PUT /home_blogs/1
# PATCH/PUT /home_blogs/1.json
private
# Use callbacks to share common setup or constraints between actions.
def set_home_blog
@home_blog = HomeBlog.find(params[:id])
end
# Never trust parameters from the scary internet, only allow the white list through.
def home_blog_params
params.require(:home_blog).permit(:name, :entry, :image)
end
end
appplication.scss
#rss-feed-div {
margin-top: 150px;
width: 100%;
background-color: #2C2C7C;
padding: 2px;
text-align: center;
border: 5px;
border-color: #95A5A6;
border-style: solid;
position: relative;
h1 {
color: white;
}
}
.cover-photo {
width: 50%;
max-width: 400px;
min-width: 150px;
max-height: 400px;
min-height: 200px;
float: left;
border: 5px;
border-color: #95A5A6;
border-style: solid;
box-shadow: 0 10px 20px rgba(0, 0, 0, 0.3);
}
.blog_post_content {
width: 80%;
margin-left: 20%;
height: 76%;
min-height: 400px;
min-width: 400px;
max-width: 800px;
padding: 10px;
margin-top: 50px;
margin-bottom: 20px;
background-color: #2C2C7C;
border: 5px;
border-color: #95A5A6;
border-style: solid;
border-radius: 20px 20px 20px 20px;
box-shadow: 0 10px 20px rgba(0, 0, 0, 0.3);
.post-title{
background-color: #8E8A89;
font-family: Impact, Charcoal, sans-serif;
font-weight: bold;
font-size: 30px;
width: 50%;
float: right;
margin-bottom: 30px;
padding: 5px;
}
.post-text {
background-color: white;
font-family: "Times New Roman", Times, serif;
padding-bottom: 10px;
float: right;
width: 50%;
padding: 4px;
p {
font-size: 15px;
}
a {
font-size: 20px;
}
}
}
.hashtags {
background-color: #8E8A89;
border-top: 5px;
border-color: #95A5A6;
border-style: solid;
float: left;
width: 100%;
padding: 5px;
margin-top: 5px;
margin-bottom: 1%;
box-shadow: 0 10px 20px rgba(0, 0, 0, 0.3);
}
.pagination {
margin-left: 25px;
background-color: white;
border: 2px;
border-style: groove;
border-color: black;
background-color: #8E8A89;
a {
color: black;
font-size: 20px;
}
}
rss_feed.html.erb
<!DOCTYPE html>
<html>
<body>
<div id="rss-feed-div"><h1><%= image_tag("icons8-rss-40.png") %>RSS Feed</h1></div>
<% if @highest_voted %>
<div id="most-popular">
<h4><b>#Trending</b></h4>
<%= link_to @highest_voted.name, @highest_voted %>
<%= image_tag @highest_voted.image.to_s %>
</div>
<% end %>
<div class="pagination"><%= will_paginate @home_blogs %></div>
<% @home_blogs.each do |p| %>
<div class="blog_post_content">
<div class="cover-photo">
<%= image_tag p.image_url(:medium).to_s %>
</div>
<div class="post-title"><b><%= p.name %> | <%= p.created_at.to_date %></b></div>
<% if p.entry.length > 200 %>
<div class="post-text">
<p><%= truncate(p.entry, :ommision => "... Read More", :length => 200, escape: false) %></p>
<%= link_to "Read more", p %><%= image_tag "icons8-chevron-right-24.png" %>
</div>
<div class="hashtags"><%= image_tag("if__hashtag_2559811.png", style: 'height:50px;width:50px;')%><b><%= p.all_hashes %></b></div>
</div>
<br />
<% end %>
<% end %>
<br />
</body>
</html>