这是我Post
控制器创建动作:未定义的方法`URL” <ActiveRecord的::协会:: CollectionProxy []>
def create
@user = current_user
@post = @user.posts.create(post_params)
respond_to do |format|
if @post.save
format.html { redirect_to @post, notice: 'Post was successfully created.' }
format.json { render :show, status: :created, location: @post }
else
format.html { render :new }
format.json { render json: @post.errors, status: :unprocessable_entity }
end
end
私人:
DEF post_params
PARAMS。要求(:post).permit( :title,:description,:size,images_attributes [:id,:image,:imageable_id,:imageable_type])
end
端
这是show.html.erb
:
(<%= image_tag @post.images.url %>)
这是Post
模型:
class Post < ActiveRecord::Base
belongs_to :user
has_many :images, as: :imageable
accepts_nested_attributes_for :images
end
这是Image
模型:
class Image < ActiveRecord::Base
belongs_to :imageable, polymorphic: true
mount_uploader :image, ImageUploader
end
图像不显示更换
:original
。 – fahad