微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

将 Ruby 脚本与 Ruby on rails 集成时出错

如何解决将 Ruby 脚本与 Ruby on rails 集成时出错

我是 Ruby 和 Ruby on rails 的新手!

我尝试了多种解决方案来解决这个问题,但没有希望!

这是下面的原始 Ruby 代码,我一直在尝试将其集成到我的 Ruby on Rails crud 应用程序中。


text = "Text"

canvas = Magick::Image.new(1000,1000) { self.background_color = "yellow" }
    gc = Magick::Draw.new
    gc.pointsize(50)
    gc.text(30,70,text.center(14))

    gc.draw(canvas)
    canvas.write("tst.png")

这是下面的控制器以及集成的 Ruby 脚本。


class PostsController < ApplicationController
  def index
    @posts = Post.all
  end

  def create
    post = Post.new(post_params)
    post.save

    redirect_to root_path
  end

  def show
    title1 = params["title"]
    image1 = params["image"]
    canvas = Magick::Image.new(1000,title1.center(14))

    gc.draw(canvas)
    canvas.write(image1)
    @post = Post.find(params[:id])
  end

  def edit
    @post = Post.find(params[:id])
  end

  def destroy
    post = Post.find(params[:id])
    post.destroy
    redirect_to root_path
  end

  def update
    post = Post.find(params[:id])
    post.update(post_params)

    redirect_to root_path
  end

  private

  def post_params
    params.require(:post).permit(:title,:description,:image)
  end
end

最后,这是我得到的错误的图像。

enter image description here

谢谢大家!

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。