【发布时间】:2017-01-02 18:59:35
【问题描述】:
我是初学者,目前正在关注 Mackenzie Child 的 Portfolio + Blog Rails Youtube 教程,以便在 Heroku 上部署网站。你可以在这里找到教程的链接:https://www.youtube.com/watch?v=62PQUaDhgqw&t=14s
我正在尝试添加友好的 id gem,但在我的终端中遇到了这个问题:
Ivys-MacBook-Pro:portfolio ivychen$ Post.find_each(&:save)
-bash: syntax error near unexpected token `&'
我不知道如何解决它。我想我可能没有正确格式化我的 post.rb 中的行,所以如果你想看一下它们就在这里:
class Post < ApplicationRecord
has_attached_file :image, styles: { large: "600x600>", medium: "300x300>", thumb: "150x150#"}
validates_attachment_content_type :image, content_type: /\Aimage\/.*\Z/
extend FriendlyId
friendly_id :title, use: :slugged
end
这是我放入 post_controller.rb 的内容:
def find_post
@post = Post.friendly.find(params[:id])
end
这可能是一个简单的解决方法,但我只是不知道该怎么做!谢谢!任何帮助将不胜感激。
【问题讨论】:
-
你的 suntax 好像错了我会试试
Post.find_each{ |post| post.save! } -
我成功了!谢谢!
标签: ruby-on-rails heroku rubygems