熱門文章

2016年7月12日 星期二

[Ruby]bulid a IG app

https://www.devwalks.com/lets-build-instagram-in-rails-part-1/


https://haml2erb.org   haml to html


在實作時出現錯誤

Please help with the Paperclips!

First things first, as per the docs, you’ll need imagemagick running on your development computer. Set it up as per the instructions here.

--------------------------------------------------------------------------------
Set the MAGICK_HOME environment variable to the path where you extracted the ImageMagick files. For example:
 export MAGICK_HOME="$HOME/ImageMagick-7.0.2"
If the bin subdirectory of the extracted package is not already in your executable search path, add it to your PATH environment variable. For example:
export PATH="$MAGICK_HOME/bin:$PATH"
Set the DYLD_LIBRARY_PATH environment variable:
export DYLD_LIBRARY_PATH="$MAGICK_HOME/lib/"
Finally, to verify ImageMagick is working properly, type the following on the command line:
magick logo: logo.gifidentify logo.gifdisplay logo.gif




--------------------------------------------------------------------------------
後來忽略,回到 https://www.devwalks.com/lets-build-instagram-in-rails-part-1/


Next we’ll add the paperclip gem to our gemfile as per their docs.
gem 'paperclip', '~> 4.2' #at the writing of this post  

Read the next bit of the docs, what does it ask you to do now?

bundle install









再上傳檔案時發生

Photo Could not run the identify command. Please install ImageMagick.

解決,
You need to change the files production.rb and development.rb which are in:
config/environments:
# Paperclip config:
Paperclip.options[:image_magick_path] = "/opt/ImageMagick/bin"
Paperclip.options[:command_path] = "/opt/ImageMagick/bin"
Just add those two lines just before the last line and restart the server.
In MacOSX system, if you are using another location, just put the right PATH there.

我的路徑是 :
Paperclip.options[:command_path] = "/Users/QJpioneer/ImageMagick-7.0.1/bin/"  Paperclip.options[:image_magick_path] = "/Users/QJpioneer/ImageMagick-7.0.1/bin/"



上傳檔案後
似乎沒有吃進去圖檔.....

用rails c 進去看




看伺服器端

Started POST "/posts" for ::1 at 2016-07-13 07:15:07 +0800Processing by PostsController#create as HTML  Parameters: {"utf8"=>"✓", "authenticity_token"=>"Qyu7WWiAJR5AV0MuzIEzfbXvoeYVDxcla+wGaWm92bwA9QScqJf+hZ3aJkvP1OutO5W3+Lgbh4AjsCtDKukVKg==", "post"=>{"image"=>#<ActionDispatch::Http::UploadedFile:0x007fc281b10ff8 @tempfile=#<Tempfile:/var/folders/js/038lfs452n362y3xc7phyz100000gn/T/RackMultipart20160713-54694-1qdykz.jpg>, @original_filename="Country life.jpg", @content_type="image/jpeg", @headers="Content-Disposition: form-data; name=\"post[image]\"; filename=\"Country life.jpg\"\r\nContent-Type: image/jpeg\r\n">, "caption"=>"123"}, "commit"=>"Create Post"}Command :: PATH=/Users/QJpioneer/ImageMagick-7.0.1/bin/:$PATH; file -b --mime '/var/folders/js/038lfs452n362y3xc7phyz100000gn/T/993316952cab27089c21a4f6fdd5299020160713-54694-1fsypu2.jpg'Command :: PATH=/Users/QJpioneer/ImageMagick-7.0.1/bin/:$PATH; identify -format '%wx%h,%[exif:orientation]' '/var/folders/js/038lfs452n362y3xc7phyz100000gn/T/b2aa763204471d9d58ed3488ce58a26b20160713-54694-1129s9z.jpg[0]' 2>/dev/null[paperclip] An error was received while processing: #<Paperclip::Errors::NotIdentifiedByImageMagickError: Paperclip::Errors::NotIdentifiedByImageMagickError>   (0.1ms)  begin transactionCommand :: PATH=/Users/QJpioneer/ImageMagick-7.0.1/bin/:$PATH; file -b --mime '/var/folders/js/038lfs452n362y3xc7phyz100000gn/T/993316952cab27089c21a4f6fdd5299020160713-54694-1e7exev.jpg'   (0.1ms)  rollback transactionRedirected to http://localhost:3000/postsCompleted 302 Found in 143ms (ActiveRecord: 0.3ms)Started GET "/posts" for ::1 at 2016-07-13 07:15:08 +0800Processing by PostsController#index as HTML  Post Load (0.2ms)  SELECT "posts".* FROM "posts"  Rendered posts/index.html.erb within layouts/application (1.1ms)Completed 200 OK in 32ms (Views: 31.3ms | ActiveRecord: 0.2ms)





嘗試解決:
reinstall homebrew  http://brew.sh <-官方

安裝homebrew
➜  IGapp git:(master) /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
It appears Homebrew is already installed. If your intent is to reinstall you
should do the following before running this installer again:
    ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/uninstall)"

The current contents of /usr/local are bin Cellar CODEOFCONDUCT.md CONTRIBUTING.md etc git heroku include lib Library LICENSE.txt opt README.md sbin share SUPPORTERS.md .git .gitignore

顯示已有homebrew必須執行以下來解除安裝:
 ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/uninstall)"


安裝最新:
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
安裝途中須按enter繼續,並輸入密碼,安裝完成。


嘗試  brew install imagemagick

➜  IGapp git:(master) brew install imagemagick
==> Installing dependencies for imagemagick: xz, libtool, jpeg, libpng, libtiff, free
==> Installing imagemagick dependency: xz
==> Downloading https://homebrew.bintray.com/bottles/xz-5.2.2.el_capitan.bottle.tar.gz
######################################################################## 100.0%
==> Pouring xz-5.2.2.el_capitan.bottle.tar.gz
🍺  /usr/local/Cellar/xz/5.2.2: 91 files, 1.4M
==> Installing imagemagick dependency: libtool
==> Downloading https://homebrew.bintray.com/bottles/libtool-2.4.6.el_capitan.bottle.tar.gz
######################################################################## 100.0%
==> Pouring libtool-2.4.6.el_capitan.bottle.tar.gz
==> Caveats
In order to prevent conflicts with Apple's own libtool we have prepended a "g"
so, you have instead: glibtool and glibtoolize.
==> Summary
🍺  /usr/local/Cellar/libtool/2.4.6: 70 files, 3.7M
==> Installing imagemagick dependency: jpeg
==> Downloading https://homebrew.bintray.com/bottles/jpeg-8d.el_capitan.bottle.2.tar.gz
######################################################################## 100.0%
==> Pouring jpeg-8d.el_capitan.bottle.2.tar.gz
🍺  /usr/local/Cellar/jpeg/8d: 19 files, 713.7K
==> Installing imagemagick dependency: libpng
==> Downloading https://homebrew.bintray.com/bottles/libpng-1.6.23.el_capitan.bottle.tar.gz
######################################################################## 100.0%
==> Pouring libpng-1.6.23.el_capitan.bottle.tar.gz
🍺  /usr/local/Cellar/libpng/1.6.23: 25 files, 1.2M
==> Installing imagemagick dependency: libtiff
==> Downloading https://homebrew.bintray.com/bottles/libtiff-4.0.6_1.el_capitan.bottle.tar.g
######################################################################## 100.0%
==> Pouring libtiff-4.0.6_1.el_capitan.bottle.tar.gz
🍺  /usr/local/Cellar/libtiff/4.0.6_1: 261 files, 3.4M
==> Installing imagemagick dependency: freetype
==> Downloading https://homebrew.bintray.com/bottles/freetype-2.6.5.el_capitan.bottle.tar.gz
######################################################################## 100.0%
==> Pouring freetype-2.6.5.el_capitan.bottle.tar.gz
🍺  /usr/local/Cellar/freetype/2.6.5: 61 files, 2.5M
==> Installing imagemagick
==> Downloading https://homebrew.bintray.com/bottles/imagemagick-6.9.5-2.el_capitan.bottle.t
######################################################################## 100.0%
==> Pouring imagemagick-6.9.5-2.el_capitan.bottle.tar.gz
🍺  /usr/local/Cellar/imagemagick/6.9.5-2: 1,464 files, 22.5M


可以執行
➜  IGapp git:(master) which convert
/usr/local/bin/convert

不過出現另一個問題

➜  IGapp git:(master) rake db:migrate
zsh: /usr/local/bin/rake: bad interpreter: /usr/local/opt/ruby/bin/ruby: no such file or directory
rake aborted!
cannot load such file -- bundler/setup
/Users/QJpioneer/railsbridge/IGapp/config/boot.rb:3:in `<top (required)>'
/Users/QJpioneer/railsbridge/IGapp/config/application.rb:1:in `<top (required)>'
/Users/QJpioneer/railsbridge/IGapp/Rakefile:4:in `<top (required)>'
(See full trace by running task with --trace)


➜  IGapp git:(master) bundle install
zsh: /usr/local/bin/bundle: bad interpreter: /usr/local/opt/ruby/bin/ruby: no such file or directory


➜  IGapp git:(master) bin/rails s
/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:55:in `require': cannot load such file -- bundler (LoadError)
from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from /Users/QJpioneer/railsbridge/IGapp/bin/spring:8:in `<top (required)>'
from bin/rails:3:in `load'
from bin/rails:3:in `<main>'

嘗試另一篇來解決


沒有留言:

張貼留言