你好我有回形针宝石的问题我搜索了互联网,但发现没有什么可以帮助我,我的代码很好,很清楚我不明白为什么它没有给我高度和我希望它的宽度只调整到自己的高度和宽度
Post.rb
class Post < ActiveRecord::Base
validates :image, presence: true
has_attached_file :image, styles: { medium: "640x" }
validates_attachment_content_type :image, content_type: /\Aimage\/.*\Z/
end
索引
<% @posts.each do |post| %>
<%= image_tag post.image.url(:medium) %><br />
<%= post.caption %>
<% end %>
发布控制器
class PostsController < ApplicationController
def index
@posts = Post.all
end
def new
@post = Post.new
end
def create
@post = Post.new(post_params)
if @post.save
redirect_to root_path
else
render 'new'
end
end
private
def post_params
params.require(:post).permit(:image, :caption)
end
end