這是我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