【发布时间】:2018-09-10 02:49:30
【问题描述】:
所以我有这些文件
deal.rb
class Deal < ApplicationRecord
has_many :images, as: :imageable, dependent: :destroy
#there is more code after this
end
image.rb
class Image < ApplicationRecord
belongs_to :imageable, polymorphic: true
belongs_to :deal
has_attached_file :attachment, styles: { thumb: "100x100!", medium: "200x200!" }
validates_attachment_content_type :attachment, content_type: /\Aimage\/.*\z/
end
deals_controller.rb
module Admins
class DealsController < BaseController
before_action :find_deal, only: [:edit, :update, :destroy]
def index
@deals = Deal.includes(:images)
end
def new
@deal = Deal.new
end
def edit
end
def create
@deal = Deal.new(deal_params.merge(created_by: current_user.id))
if @deal.save
flash[:success] = t('.success')
redirect_to admins_deals_url
else
flash.now[:warning] = t('.failure')
render :new
end
end
def update
if @deal.update(deal_params)
flash[:success] = t('.success')
redirect_to admins_deals_url
else
flash.now[:warning] = @deal.errors[:base].to_sentence
render :edit
end
end
def destroy
if @deal.destroy
flash[:success] = t('.success')
redirect_to admins_deals_url
else
flash.now[:warning] = t('.failure')
render :index
end
end
private
def deal_params
params.require(:deal).permit(:title, :description, :price, :discounted_price, :quantity, :publish_date, images_attributes: [:id, :attachment, :_destroy])
end
def find_deal
@deal = Deal.find_by(id: params[:id])
unless @deal
flash[:warning] = t('deals.not_found')
redirect_to admins_deals_path
end
end
end
end
application_controller.rb
class ApplicationController < ActionController::Base
helper_method :current_user, :current_cart
def current_user
@current_user ||= User.find_by(id: current_user_id)
end
def current_user_id
cookies.signed[:user_id] || session[:user_id]
end
def current_cart
@current_cart ||= (current_user.addressed_cart || current_user.cart) if current_user
end
end
编辑: 虽然我不认为 application_controller 与错误有任何关系
我正在创建与嵌套图像属性的交易。我正在使用回形针上传图像。但我收到了这些错误。我不知道这些错误是什么意思。这是显示错误的图像。
这是 pastebin 链接 errors on terminal on creating deal
【问题讨论】:
-
请将您的错误也发布到
https://pastebin.com之类的地方。some merge error是什么意思?如果您更改了代码,我们需要查看 git 历史记录。 -
错误还会告诉您
application_controller.rb:5上的一些信息,因此也可能是该区域的邮政编码。另见github.com/thoughtbot/paperclip/issues/2576 -
@lacostenycoder 是的,我看到了。但是没有关于那个的回复。
-
@lacostenycoder 我认为这不是我的错误
标签: ruby-on-rails ruby rubygems paperclip