2017-01-02 29 views
0

我是一名初學者,我目前正在關注Mackenzie Child's Portfolio + Blog Rails Youtube教程在Heroku上部署網站。你可以找到鏈接到教程這裏:https://www.youtube.com/watch?v=62PQUaDhgqw&t=14s語法錯誤彈出試圖添加友好的ID寶石

我想補充的友好ID寶石,但我遇到了這個問題,在我的終端:

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 

這可能是一個簡單的修復,但我只是不知道該怎麼做!謝謝!任何幫助將不勝感激。

+0

您suntax似乎是錯誤的,我會試着去'Post.find_each {|文章| post.save! }' – tomtomtom

+0

我明白了!謝謝! –

回答

1

導航到您的rails項目目錄並運行'rails c'進入rails控制檯,您可以在其中編寫ruby代碼並加載軌道。

/rails/myproject $ rails c 
Running via Spring preloader in process 81138 
Loading development environment (Rails 5.0.0.1) 
irb(main):001:0> Post.find_each(&:save) 

您正試圖在bash(終端)中評估ruby/rails代碼,當您需要在rails控制檯中時。

+0

修好了!非常感謝你! :) –

0

你應該在鐵軌控制檯運行Post.find_each(&:save)rails c

+0

明白了!謝謝! –