RMagick は、画像上のテキストを自動折り返しし、そのテキストにブレークラインを追加することになっています。これを行うための私のコードは次のとおりです。
def word_wrap(text, columns = 80)
text.split("\n").collect do |line|
line.length > columns ? line.gsub(/(.{1, #{columns}})(\s+|$)/, "\\1\n").strip : line
end * "\n"
end
process :caption
def caption
manipulate! do |source|
txt = Magick::Draw.new
txt.font_family = "Impact"
txt.fill = "#ffffff"
position = 80
top_caption = model.top_caption
word_wrap(top_caption, 90).split("\n").each do |row|
source.annotate(txt, 0, 0, 0, position +=20, row)
end
end
end
end
そして、私はこのエラーを受け取ります:
(asasfasf は、私がテキストに書いたテキストです - top_caption)
NoMethodError in AnswersController#create
undefined method `write' for ["asasfasf"]:Array
app/uploaders/answer_uploader.rb:53:in `caption'
app/controllers/answers_controller.rb:11:in `create'
アクションの作成:
def create
@answer = Answer.new(params[:answer])
@answer.user_id = current_user.id
@answer.picture_id = daily_picture.id
@answer.answer = daily_picture.image
if @answer.save
redirect_to root_path
end
end
およびコンソールのエラー:
Completed 500 Internal Server Error in 69ms
NoMethodError (undefined method `annotate' for #<Picture:0x007ffd2f578c88>):
app/uploaders/answer_uploader.rb:64:in `block (2 levels) in caption'
app/uploaders/answer_uploader.rb:63:in `each'
app/uploaders/answer_uploader.rb:63:in `block in caption'
app/uploaders/answer_uploader.rb:53:in `caption'
app/controllers/answers_controller.rb:11:in `create'
コードのどこに問題がありますか?
ありがとう!