galetahub-simple_captcha gem不显示StandardError(运行convert时出错:convert:无法读取字体

时间:2013-06-26 14:02:43

标签: ruby-on-rails-3 imagemagick captcha

我添加了simple_captcha gem,当我加载它所在的表单时,我在服务器中收到错误。我不知道如何解决这个问题。判断我在谷歌上所做的研究似乎是一个ImageMagick问题,但我并不完全确定。

SimpleCaptcha::SimpleCaptchaData Load (0.2ms)  SELECT "simple_captcha_data".* FROM "simple_captcha_data" WHERE "simple_captcha_data"."key" = '406a6bd66e520eef7f24a13c2cc8c5b23d3749e8' LIMIT 1
  CACHE (0.0ms)  SELECT "simple_captcha_data".* FROM "simple_captcha_data" WHERE "simple_captcha_data"."key" = '406a6bd66e520eef7f24a13c2cc8c5b23d3749e8' LIMIT 1

StandardError (Error while running convert: convert: unable to read font `/usr/local/share/ghostscript/fonts/n019003l.pfb' @ error/annotate.c/RenderFreetype/1125.
convert: Postscript delegate failed `/var/tmp/magick-4563zAoZ5QYyFe6C': No such file or directory @ error/ps.c/ReadPSImage/833.
convert: no images defined `/var/folders/6b/tq59gs0d1f7bp_zg41cf6fqm0000gn/T/simple_captcha20130626-4555-1yk8sq1.jpg' @ error/convert.c/ConvertImageCommand/3078.
):

simple_capthca.rb

SimpleCaptcha.setup do |sc|
  # default: 100x28
  sc.image_size = '120x40'

  # default: 5
  sc.length = 6

  # default: simply_blue
  # possible values:
  # 'embosed_silver',
  # 'simply_red',
  # 'simply_green',
  # 'simply_blue',
  # 'distorted_black',
  # 'all_black',
  # 'charcoal_grey',
  # 'almost_invisible'
  # 'random'
  sc.image_style = 'simply_green'

  # default: low
  # possible values: 'low', 'medium', 'high', 'random'
  sc.distortion = 'medium'

  sc.image_magick_path = '/usr/local/bin/' # you can check this from console by running: which convert'

end

reservations_controller.rb

  def create
    @restaurant = Restaurant.find(params[:restaurant_id])
    @reservation = @restaurant.reservations.build(date: DateTime.new(params[:date]["date(1i)"].to_i, params[:date]["date(2i)"].to_i, params[:date]["date(3i)"].to_i), time: (params[:time][:hour]).to_i)
    if @reservation.valid_with_captcha?
      @reservation.save
      @restaurant.owner.send_reservation_notification(@reservation)
      redirect_to restaurant_path(Restaurant.find(params[:restaurant_id]))
    else
      flash[:error] = "Captcha incorrect. You enterd the wrong digits." 
      redirect_to :back
    end
  end

new.html.erb

<h1>Reserve your table.</h1>
<br/>

<div class="reservation-form">
<%= form_for([@restaurant, @reservation]) do |f| %>
    <%= date_select :date, "date"  %><br/>
    <%= select_hour Time.now, :ampm => true, :prefix => :time %><br/><br/>
    <%= f.simple_captcha :label => "Prove that you're not a robot." %><br/>
    <%= f.submit "Make reservation", class: "btn btn-primary" %>
<% end %>
</div>

Reservation.rb

class Reservation < ActiveRecord::Base
  attr_accessible :restaurant_id, :date, :time
  belongs_to :restaurant
  apply_simple_captcha
end

1 个答案:

答案 0 :(得分:0)

您可能需要在安装ghostscript后安装imagemagic