gpt4 book ai didi

ruby-on-rails - 如何解决 NotIdentifiedByImageMagickError?

转载 作者:太空宇宙 更新时间:2023-11-03 16:48:48 25 4
gpt4 key购买 nike

当我点击“创建用户”按钮时,出现以下错误:

Avatar Paperclip::Errors::NotIdentifiedByImageMagickError

我的代码片段如下:

gem 文件

source 'https://rubygems.org'


# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.1.7'

# Use sqlite3 as the database for Active Record
gem 'sqlite3'

# Use SCSS for stylesheets
gem 'sass-rails', '~> 4.0.3'

# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'

# Use CoffeeScript for .js.coffee assets and views
gem 'coffee-rails', '~> 4.0.0'

# See https://github.com/sstephenson/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby

# Use jquery as the JavaScript library
gem 'jquery-rails'

# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
gem 'turbolinks'

# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 1.2'

group :doc do
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', require: false
end

# Paperclip gem for managing file uploads
gem 'paperclip', '~> 3.0'
gem 'tzinfo-data', platforms: [:x64_mingw, :mingw, :mswin]
# Use ActiveModel has_secure_password
# gem 'bcrypt-ruby', '~> 3.0.0'

# Use unicorn as the app server
# gem 'unicorn'

# Use Capistrano for deployment
# gem 'capistrano', group: :development

# Use debugger
# gem 'debugger', group: [:development, :test]

views/users/index.html.erb

<table>
<thead>
<tr>
<th>Name</th>
<th>Original Avatar</th>
<th>Thumbnail Avatar</th>
<th>Resume Filename</th>
</tr>
</thead>

<tbody>
<% @users.each do |user| %>
<tr>
<td><%= user.name %></td>
<!-- display the avatar in both the original size and the thumbnail size -->
<td><%= image_tag user.avatar.url %></td>
<td><%= image_tag user.avatar.url(:thumb) %></td>

<!-- show the filename for the resume -->
<td><%= user.resume_file_name %></td>
</tr>
<% end %>
</tbody>
</table>

<br>

<%= link_to 'New User', new_user_path %>

views/users/new.html.erb

<h1>New user</h1>

<%= render 'form' %>

<%= link_to 'Back', users_path %>

views/users/_form.html.erb

<%= form_for(@user) do |f| %>
<% if @user.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@user.errors.count, "error") %> prohibited this user from being saved:</h2>

<ul>
<% @user.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>

<div class="field">
<%= f.label :name %><br>
<%= f.text_field :name %>
</div>
<!-- Upload your attachments via a simple file_fields in the form -->
<div class="field">
<%= f.label :avatar %><br>
<%= f.file_field :avatar %>
</div>
<div class="field">
<%= f.label :resume %><br>
<%= f.file_field :resume %>
</div>
<div class="actions">
<%= f.submit %>
</div>
<% end %>

Controller /用户 Controller .rb

class UsersController < ApplicationController
# GET /users
def index
@users = User.all
end

# GET /users/new
def new
@user = User.new
end

# POST /users
def create
@user = User.new(user_params)

if @user.save
redirect_to action: 'index', notice: 'User was successfully created.'
else
render action: 'new', alert: 'User could not be created'
end
end

private

# Never trust parameters from the scary internet, only allow the white list through.
def user_params
params.require(:user).permit(:name, :avatar, :resume)
end
end

模型/用户.rb

class User < ActiveRecord::Base
#specify that the avatar is a paperclip file attachment
#specify additional styles that you want to use in views or eslewhere
has_attached_file :avatar, :styles => {:thumb => "100x100>"}

#specify that the resume is a paperclip file attachment
has_attached_file :resume

end

配置/环境/开发.rb

Rails.application.configure do
# Settings specified here will take precedence over those in config/application.rb.

# In the development environment your application's code is reloaded on
# every request. This slows down response time but is perfect for development
# since you don't have to restart the web server when you make code changes.
config.cache_classes = false

# Do not eager load code on boot.
config.eager_load = false

# Show full error reports and disable caching.
config.consider_all_requests_local = true
config.action_controller.perform_caching = false

# Don't care if the mailer can't send.
config.action_mailer.raise_delivery_errors = false

# Print deprecation notices to the Rails logger.
config.active_support.deprecation = :log

# Raise an error on page load if there are pending migrations.
config.active_record.migration_error = :page_load

# Debug mode disables concatenation and preprocessing of assets.
# This option may cause significant delays in view rendering with a large
# number of complex assets.
config.assets.debug = true

# Adds additional error checking when serving assets at runtime.
# Checks for improperly declared sprockets dependencies.
# Raises helpful error messages.
config.assets.raise_runtime_errors = true
Paperclip.options[:command_path] = 'C:\Program Files\ImageMagick-6.9.0-Q16'
# Raises error for missing translations
# config.action_view.raise_on_missing_translations = true
end

我已经在我的系统上安装了 ImageMagick-6.9.0-Q16。我正在使用 rails-4 和 ruby​​-1.9.3。

如果能帮助我找到解决方案,我将不胜感激。提前致谢。

最佳答案

这很可能是由于 Paperclip 尚未跟上的可卡因 4 中的 API 更改引起的。通过将此行插入 Gemfile 来尝试使用早期版本的可卡因:

gem “可卡因”,“= 0.3.2”

关于ruby-on-rails - 如何解决 NotIdentifiedByImageMagickError?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27565920/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com