Rails适用于本地但不适用于互联网

时间:2013-12-09 10:52:42

标签: ruby-on-rails ruby heroku amazon-s3

我正在处理一个处理图片的网络应用程序。我使用Ruby on rails,Heroku和图片,上传完成感谢回形针和亚马逊AWS S3上的存储。

当我在本地测试它时,它运行得很好,但是当我提交它并在网上测试它时,它不起作用!我可以选择要上传的文件但是当我提交时,我有一个错误:

We're sorry, but something went wrong.

If you are the application owner check the logs for more information.

图像不在亚马逊上。

这是我的代码:

观点: photo.html.erb:

<h1>New photo</h1>


<%= form_for @photo, :html => { :multipart => true } do |f| %>
  <div class="field">
  <%= f.file_field :image %>
  </div>

  <div class="action">
  <%= f.submit %>
  </div>


<% end %> 

* show.html.erb *

型号: photo.rb:

class Photo < ActiveRecord::Base
has_attached_file :image,
                :styles => { :medium => "x300", :thumb => "x100" },
                :default_url => "www.google.fr",
                :storage => :s3,
                :s3_host_name => 's3-eu-west-1.amazonaws.com',
                :bucket => 'pyloriruc',
                :s3_credentials => S3_CREDENTIALS
end

环境/初始化程序: s3.rb:

if Rails.env == "production"
     # set credentials from ENV hash
 S3_CREDENTIALS = { :access_key_id => 'AKI*****************', :secret_access_key => 'Aiqpd******************************', :bucket => 'pyloriruc'}
 else
     # get credentials from YML file
     S3_CREDENTIALS = Rails.root.join("config/s3.yml")
 end

 if Rails.env == "development"
     # set credentials from ENV hash
 S3_CREDENTIALS = { :access_key_id => 'A*************', :secret_access_key => 'Aiq************************', :bucket => 'pyloriruc'}
 else
     # get credentials from YML file
     S3_CREDENTIALS = Rails.root.join("config/s3.yml")
 end

这里我的heroku记录:

2013-12-06T19:13:19.602146+00:00 heroku[router]: at=info method=GET path=/ host=peaceful-coast-9294.herokuapp.com fwd="46.162.90.188" dyno=web.1 connect=3ms service=220ms status=304 bytes=0
2013-12-06T19:13:20.118326+00:00 heroku[router]: at=info method=GET path=/favicon.ico host=peaceful-coast-9294.herokuapp.com fwd="46.162.90.188" dyno=web.1 connect=2ms service=6ms status=200 bytes=0
2013-12-06T19:14:05.732585+00:00 heroku[router]: at=info method=GET path=/favicon.ico host=peaceful-coast-9294.herokuapp.com fwd="46.162.90.188" dyno=web.1 connect=5ms service=9ms status=304 bytes=0
2013-12-06T20:16:59.789769+00:00 heroku[web.1]: Idling
2013-12-06T20:16:59.791103+00:00 heroku[web.1]: State changed from up to down
2013-12-06T20:17:02.282801+00:00 heroku[web.1]: Stopping all processes with SIGTERM
2013-12-06T20:17:02.811989+00:00 app[web.1]: [2013-12-06 20:17:02] FATAL SignalException: SIGTERM
2013-12-06T20:17:02.811989+00:00 app[web.1]:    /app/vendor/ruby-2.0.0/lib/ruby/2.0.0/webrick/server.rb:170:in `select'
2013-12-06T20:17:02.811989+00:00 app[web.1]:    /app/vendor/ruby-2.0.0/lib/ruby/2.0.0/webrick/server.rb:170:in `block in start'
2013-12-06T20:17:02.811989+00:00 app[web.1]:    /app/vendor/ruby-2.0.0/lib/ruby/2.0.0/webrick/server.rb:32:in `start'
2013-12-06T20:17:02.811989+00:00 app[web.1]:    /app/vendor/ruby-2.0.0/lib/ruby/2.0.0/webrick/server.rb:160:in `start'
2013-12-06T20:17:02.811989+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.0.0/gems/rack-1.5.2/lib/rack/handler/webrick.rb:14:in `run'
2013-12-06T20:17:02.811989+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.0.0/gems/rack-1.5.2/lib/rack/server.rb:264:in `start'
2013-12-06T20:17:02.811989+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.0.0/gems/railties-4.0.0/lib/rails/commands/server.rb:84:in `start'
2013-12-06T20:17:02.811989+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.0.0/gems/railties-4.0.0/lib/rails/commands.rb:78:in `block in <top (required)>'
2013-12-06T20:17:02.811989+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.0.0/gems/railties-4.0.0/lib/rails/commands.rb:73:in `tap'
2013-12-06T20:17:02.812177+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.0.0/gems/railties-4.0.0/lib/rails/commands.rb:73:in `<top (required)>'
2013-12-06T20:17:02.812177+00:00 app[web.1]:    bin/rails:4:in `require'
2013-12-06T20:17:02.812177+00:00 app[web.1]:    bin/rails:4:in `<main>'
2013-12-06T20:17:02.812177+00:00 app[web.1]: [2013-12-06 20:17:02] INFO  going to shutdown ...
2013-12-06T20:17:02.812177+00:00 app[web.1]: [2013-12-06 20:17:02] INFO  WEBrick::HTTPServer#start done.
2013-12-06T20:17:02.812177+00:00 app[web.1]: Exiting
2013-12-06T20:17:04.087930+00:00 heroku[web.1]: Process exited with status 143
2013-12-09T10:36:19+00:00 heroku[slug-compiler]: Slug compilation started
2013-12-09T10:37:20.827034+00:00 heroku[api]: Deploy 8bc5094 by oriane.blot@gmail.com
2013-12-09T10:37:20.858563+00:00 heroku[api]: Release v26 created by oriane.blot@gmail.com
2013-12-09T10:37:21+00:00 heroku[slug-compiler]: Slug compilation finished
2013-12-09T10:37:21.137210+00:00 heroku[web.1]: State changed from down to starting
2013-12-09T10:37:28.390223+00:00 heroku[web.1]: Starting process with command `bin/rails server -p 37269 -e $RAILS_ENV`
2013-12-09T10:37:34.913910+00:00 app[web.1]: /app/config/initializers/s3.rb:14: warning: already initialized constant S3_CREDENTIALS
2013-12-09T10:37:34.914393+00:00 app[web.1]: /app/config/initializers/s3.rb:3: warning: previous definition of S3_CREDENTIALS was here
2013-12-09T10:37:36.714619+00:00 app[web.1]: [2013-12-09 10:37:36] INFO  WEBrick::HTTPServer#start: pid=2 port=37269
2013-12-09T10:37:36.714432+00:00 app[web.1]: [2013-12-09 10:37:36] INFO  ruby 2.0.0 (2013-11-22) [x86_64-linux]
2013-12-09T10:37:36.714432+00:00 app[web.1]: [2013-12-09 10:37:36] INFO  WEBrick 1.3.1
2013-12-09T10:37:37.025820+00:00 heroku[web.1]: State changed from starting to up
2013-12-09T10:38:03.402474+00:00 app[web.1]: => Rails 4.0.0 application starting in production on http://0.0.0.0:37269
2013-12-09T10:38:03.402474+00:00 app[web.1]: => Booting WEBrick
2013-12-09T10:38:03.402474+00:00 app[web.1]: => Run `rails server -h` for more startup options
2013-12-09T10:38:03.402474+00:00 app[web.1]: Started GET "/" for 130.240.98.83 at 2013-12-09 10:38:03 +0000
2013-12-09T10:38:03.402474+00:00 app[web.1]: [fog][WARNING] Unable to load the 'unf' gem. Your AWS strings may not be properly encoded.
2013-12-09T10:38:03.402474+00:00 app[web.1]: => Ctrl-C to shutdown server
2013-12-09T10:38:03.402474+00:00 app[web.1]: Started GET "/" for 130.240.98.83 at 2013-12-09 10:38:03 +0000
2013-12-09T10:38:03.650432+00:00 app[web.1]: Processing by PhotosController#new as HTML
2013-12-09T10:38:03.650432+00:00 app[web.1]: Processing by PhotosController#new as HTML
2013-12-09T10:38:05.045246+00:00 app[web.1]:   Rendered photos/new.html.erb within layouts/application (1069.7ms)
2013-12-09T10:38:05.045246+00:00 app[web.1]:   Rendered photos/new.html.erb within layouts/application (1069.7ms)
2013-12-09T10:38:05.067895+00:00 app[web.1]: Completed 200 OK in 1415ms (Views: 1115.1ms | ActiveRecord: 52.5ms)
2013-12-09T10:38:05.067895+00:00 app[web.1]: Completed 200 OK in 1415ms (Views: 1115.1ms | ActiveRecord: 52.5ms)
2013-12-09T10:38:05.505570+00:00 heroku[router]: at=info method=GET path=/assets/application-003b2ae11a16edbe4163053e54e0144b.js host=peaceful-coast-9294.herokuapp.com fwd="130.240.98.83" dyno=web.1 connect=1ms service=61ms status=304 bytes=0
2013-12-09T10:38:06.030429+00:00 heroku[router]: at=info method=GET path=/favicon.ico host=peaceful-coast-9294.herokuapp.com fwd="130.240.98.83" dyno=web.1 connect=6ms service=12ms status=200 bytes=0
2013-12-09T10:38:05.084218+00:00 heroku[router]: at=info method=GET path=/ host=peaceful-coast-9294.herokuapp.com fwd="130.240.98.83" dyno=web.1 connect=1ms service=1698ms status=200 bytes=1019
2013-12-09T10:38:19.118875+00:00 app[web.1]: Started POST "/photos" for 130.240.98.83 at 2013-12-09 10:38:19 +0000
2013-12-09T10:38:19.120442+00:00 app[web.1]: Started POST "/photos" for 130.240.98.83 at 2013-12-09 10:38:19 +0000
2013-12-09T10:38:19.132564+00:00 app[web.1]: Processing by PhotosController#create as HTML
2013-12-09T10:38:19.137843+00:00 app[web.1]:   Parameters: {"utf8"=>"✓", "authenticity_token"=>"Ugb5o4Yg/RlN97qqlciVhY80Y02focv6qiQgYXKAiXE=", "photo"=>{"image"=>#<ActionDispatch::Http::UploadedFile:0x007fbebb36efd0 @tempfile=#<Tempfile:/tmp/RackMultipart20131209-2-11ow38t>, @original_filename="555.png", @content_type="image/png", @headers="Content-Disposition: form-data; name=\"photo[image]\"; filename=\"555.png\"\r\nContent-Type: image/png\r\n">}, "commit"=>"Create Photo"}
2013-12-09T10:38:19.135926+00:00 app[web.1]: Processing by PhotosController#create as HTML
2013-12-09T10:38:19.137628+00:00 app[web.1]:   Parameters: {"utf8"=>"✓", "authenticity_token"=>"Ugb5o4Yg/RlN97qqlciVhY80Y02focv6qiQgYXKAiXE=", "photo"=>{"image"=>#<ActionDispatch::Http::UploadedFile:0x007fbebb36efd0 @tempfile=#<Tempfile:/tmp/RackMultipart20131209-2-11ow38t>, @original_filename="555.png", @content_type="image/png", @headers="Content-Disposition: form-data; name=\"photo[image]\"; filename=\"555.png\"\r\nContent-Type: image/png\r\n">}, "commit"=>"Create Photo"}
2013-12-09T10:38:19.161078+00:00 app[web.1]: 
2013-12-09T10:38:19.161078+00:00 app[web.1]: 
2013-12-09T10:38:19.164850+00:00 app[web.1]: 
2013-12-09T10:38:19.161078+00:00 app[web.1]: Paperclip::Error (Photo model missing required attr_accessor for 'image_file_name'):
2013-12-09T10:38:19.161078+00:00 app[web.1]:   app/controllers/photos_controller.rb:27:in `create'
2013-12-09T10:38:19.151566+00:00 app[web.1]: Completed 500 Internal Server Error in 13ms
2013-12-09T10:38:19.164850+00:00 app[web.1]: Paperclip::Error (Photo model missing required attr_accessor for 'image_file_name'):
2013-12-09T10:38:19.161078+00:00 app[web.1]: 
2013-12-09T10:38:19.153866+00:00 app[web.1]: Completed 500 Internal Server Error in 13ms
2013-12-09T10:38:19.164850+00:00 app[web.1]:   app/controllers/photos_controller.rb:27:in `create'
2013-12-09T10:38:19.164850+00:00 app[web.1]: 
2013-12-09T10:38:19.164850+00:00 app[web.1]: 
2013-12-09T10:38:19.472243+00:00 heroku[router]: at=info method=GET path=/favicon.ico host=peaceful-coast-9294.herokuapp.com fwd="130.240.98.83" dyno=web.1 connect=0ms service=8ms status=304 bytes=0
2013-12-09T10:38:19.166740+00:00 heroku[router]: at=info method=POST path=/photos host=peaceful-coast-9294.herokuapp.com fwd="130.240.98.83" dyno=web.1 connect=4ms service=7348ms status=500 bytes=1266
2013-12-09T10:38:05.498347+00:00 heroku[router]: at=info method=GET path=/assets/application-f5232013e5e376066072368171046674.css host=peaceful-coast-9294.herokuapp.com fwd="130.240.98.83" dyno=web.1 connect=0ms service=45ms status=304 bytes=0
2013-12-09T10:45:10.693758+00:00 app[web.1]: Started GET "/" for 130.240.98.83 at 2013-12-09 10:45:10 +0000
2013-12-09T10:45:10.693758+00:00 app[web.1]: Started GET "/" for 130.240.98.83 at 2013-12-09 10:45:10 +0000
2013-12-09T10:45:10.695539+00:00 app[web.1]: Processing by PhotosController#new as HTML
2013-12-09T10:45:10.695539+00:00 app[web.1]: Processing by PhotosController#new as HTML
2013-12-09T10:45:10.703697+00:00 app[web.1]: Completed 200 OK in 8ms (Views: 6.3ms | ActiveRecord: 0.0ms)
2013-12-09T10:45:10.702562+00:00 app[web.1]:   Rendered photos/new.html.erb within layouts/application (3.8ms)
2013-12-09T10:45:10.703697+00:00 app[web.1]: Completed 200 OK in 8ms (Views: 6.3ms | ActiveRecord: 0.0ms)
2013-12-09T10:45:10.702562+00:00 app[web.1]:   Rendered photos/new.html.erb within layouts/application (3.8ms)
2013-12-09T10:45:10.710025+00:00 heroku[router]: at=info method=GET path=/ host=peaceful-coast-9294.herokuapp.com fwd="130.240.98.83" dyno=web.1 connect=9ms service=24ms status=304 bytes=0
2013-12-09T10:45:11.431079+00:00 heroku[router]: at=info method=GET path=/favicon.ico host=peaceful-coast-9294.herokuapp.com fwd="130.240.98.83" dyno=web.1 connect=7ms service=8ms status=304 bytes=0
2013-12-09T10:45:21.443872+00:00 app[web.1]: Started POST "/photos" for 130.240.98.83 at 2013-12-09 10:45:21 +0000
2013-12-09T10:45:21.443872+00:00 app[web.1]: Started POST "/photos" for 130.240.98.83 at 2013-12-09 10:45:21 +0000
2013-12-09T10:45:21.455609+00:00 app[web.1]:   Parameters: {"utf8"=>"✓", "authenticity_token"=>"Ugb5o4Yg/RlN97qqlciVhY80Y02focv6qiQgYXKAiXE=", "photo"=>{"image"=>#<ActionDispatch::Http::UploadedFile:0x007fbebb2d8b48 @tempfile=#<Tempfile:/tmp/RackMultipart20131209-2-1hsoowg>, @original_filename="555.png", @content_type="image/png", @headers="Content-Disposition: form-data; name=\"photo[image]\"; filename=\"555.png\"\r\nContent-Type: image/png\r\n">}, "commit"=>"Create Photo"}
2013-12-09T10:45:21.455609+00:00 app[web.1]: Processing by PhotosController#create as HTML
2013-12-09T10:45:21.459039+00:00 app[web.1]: Completed 500 Internal Server Error in 3ms
2013-12-09T10:45:21.455609+00:00 app[web.1]: Processing by PhotosController#create as HTML
2013-12-09T10:45:21.461025+00:00 app[web.1]: Paperclip::Error (Photo model missing required attr_accessor for 'image_file_name'):
2013-12-09T10:45:21.455609+00:00 app[web.1]:   Parameters: {"utf8"=>"✓", "authenticity_token"=>"Ugb5o4Yg/RlN97qqlciVhY80Y02focv6qiQgYXKAiXE=", "photo"=>{"image"=>#<ActionDispatch::Http::UploadedFile:0x007fbebb2d8b48 @tempfile=#<Tempfile:/tmp/RackMultipart20131209-2-1hsoowg>, @original_filename="555.png", @content_type="image/png", @headers="Content-Disposition: form-data; name=\"photo[image]\"; filename=\"555.png\"\r\nContent-Type: image/png\r\n">}, "commit"=>"Create Photo"}
2013-12-09T10:45:21.459039+00:00 app[web.1]: Completed 500 Internal Server Error in 3ms
2013-12-09T10:45:21.461025+00:00 app[web.1]: 
2013-12-09T10:45:21.461025+00:00 app[web.1]: 
2013-12-09T10:45:21.461025+00:00 app[web.1]:   app/controllers/photos_controller.rb:27:in `create'
2013-12-09T10:45:21.461025+00:00 app[web.1]: 
2013-12-09T10:45:21.461025+00:00 app[web.1]: 
2013-12-09T10:45:21.461025+00:00 app[web.1]: 
2013-12-09T10:45:21.461025+00:00 app[web.1]:   app/controllers/photos_controller.rb:27:in `create'
2013-12-09T10:45:21.461025+00:00 app[web.1]: Paperclip::Error (Photo model missing required attr_accessor for 'image_file_name'):
2013-12-09T10:45:21.461025+00:00 app[web.1]: 
2013-12-09T10:45:21.477021+00:00 heroku[router]: at=info method=POST path=/photos host=peaceful-coast-9294.herokuapp.com fwd="130.240.98.83" dyno=web.1 connect=1ms service=4964ms status=500 bytes=1266

我不知道您是否需要更多代码来帮助我解决此问题。谢谢。

1 个答案:

答案 0 :(得分:1)

尝试

if Rails.env == "production"
     # set credentials from ENV hash
 S3_CREDENTIALS = { :access_key_id => 'AKI*****************', :secret_access_key => 'Aiqpd******************************', :bucket => 'pyloriruc'}
 else
     # get credentials from YML file
     S3_CREDENTIALS = { :access_key_id => 'AKI*****************', :secret_access_key => 'Aiqpd******************************', :bucket => 'pyloriruc'}
 end

只是为了看看它是否可以解决你的问题,然后才能制作出更好的代码..