Ruby on rails RubyonRails动态存储映像不';我没有出现
我正在开发一款应用程序,它在使用活动存储之前运行良好。但我不确定发生了什么,但它不再工作了,它显示了一个损坏的图像: 以下是我过去在联系人模型上所做的:Ruby on rails RubyonRails动态存储映像不';我没有出现,ruby-on-rails,ruby,Ruby On Rails,Ruby,我正在开发一款应用程序,它在使用活动存储之前运行良好。但我不确定发生了什么,但它不再工作了,它显示了一个损坏的图像: 以下是我过去在联系人模型上所做的: has_one_attached :contact_avatar 在我的视图/index.html.erb中: <%= image_tag contact.contact_avatar.attached? ? contact.contact_avatar : "100x100.png", class: "media-objec
has_one_attached :contact_avatar
在我的视图/index.html.erb
中:
<%= image_tag contact.contact_avatar.attached? ? contact.contact_avatar : "100x100.png", class: "media-object img-thumbnail img-rounded mr-3" %>
这是联系人控制器:
class ContactsController < ApplicationController
before_action :set_contact, only: [:show, :edit, :update, :destroy]
skip_before_action :verify_authenticity_token, only: [:destroy]
before_action :authenticate_user!
def index
@contacts = current_user.contacts.order(created_at: :desc).page(params[:page])
@contacts = @contacts.where(category_id: params[:category_id]) if params[:category_id].present?
@contacts = @contacts.search(params[:term]) if params[:term].present?
end
def autocomplete
@contacts = current_user.contacts.order(created_at: :desc).page(params[:page])
@contacts = @contacts.where(category_id: params[:category_id]) if params[:category_id].present?
@contacts = @contacts.search(params[:term]) if params[:term].present?
render json: @contacts.map { |contact| { id: contact.id, value: contact.name }}
end
def show
end
def new
@contact = Contact.new
end
def edit
authorize @contact
end
def create
@contact = current_user.contacts.build(contact_params)
@success = @contact.save ? true : false
respond_to do |format|
if @success
format.html { redirect_to contacts_path, notice: 'Contact was successfully created.' }
format.js
else
format.js
end
end
end
def update
@success = @contact.update(contact_params) ? true : false
respond_to do |format|
if @success
format.html { redirect_to contacts_path, notice: 'Contact was successfully updated.' }
format.js
else
format.js
end
end
end
def destroy
authorize @contact
@contact.destroy
respond_to do |format|
format.html { redirect_to contacts_url, notice: 'Contact was successfully destroyed.' }
format.json { head :no_content }
end
end
private
def set_contact
@contact = Contact.find(params[:id])
end
def contact_params
params.require(:contact).permit(:name, :email, :mobile, :phone, :country, :address, :city, :state, :zip, :note, :category_id, :contact_avatar)
end
def has_error?(resource, field)
resource.errors.messages[field].present?
end
def get_error(resource, field)
msg = resource.errors.messages[field]
field.to_s.capitalize + " " + msg.join(' and ') + '.'
end
helper_method :has_error?
helper_method :get_error
end
将这些gem添加到gemfile并运行bundle
#Gemfile
gem 'image_processing'
gem 'mini_magick'
你还需要跑步
sudo apt随后在控制台中安装imagemagick
。将这些gems添加到gemfile并运行bundle
#Gemfile
gem 'image_processing'
gem 'mini_magick'
你还需要跑步
sudo apt随后在您的控制台中安装imagemagick
。您能否发布路由文件中与错误控制器#页面(未找到)相关的部分
我猜您可能有一条通向此控制器的全面路由,这导致ActiveStorage路由永远不匹配
例如,如果你有
match '*any', to: 'errors#page_not_found', via: [:get]
然后您应该删除此选项,并研究如何配置以提供自定义错误页。您是否可以发布路由文件中与
ErrorsController\page\u not\u found
相关的部分
我猜您可能有一条通向此控制器的全面路由,这导致ActiveStorage路由永远不匹配
例如,如果你有
match '*any', to: 'errors#page_not_found', via: [:get]
然后您应该删除它,并研究如何配置以提供自定义错误页面