权限被拒绝@ dir_s_mkdir - / listings

时间:2017-02-10 01:49:46

标签: ruby-on-rails ruby permission-denied

我不确定我做错了什么。回形针与S3。

Errno :: ListingsController中的EACCES#update 权限被拒绝@ dir_s_mkdir - / listing 提取的来源(第44行):

  1. def update
  2. respond_to do | format |
  3. if @ listing.update(listing_params)
  4. format.html {redirect_to @listing,注意:'列表已成功更新。' }
  5. format.json {render:show,status :: ok,location:@listing} 48其他
  6. Listing_controller.rb

    <p id="notice"><%= notice %></p>
    
    <div class="row">
      <div class="col-md-6">
        <div class="thumbnail">
          <%= image_tag @listing.image.url %>
        </div>
      </div>
      <div class="col-md-6">
        <h3><%= @listing.name %></h3>
        <p><%= number_to_currency (@listing.price) %></p>
        <p><%= @listing.description %></p>
      </div>
    </div>
    
    <%= link_to 'Edit', edit_listing_path(@listing), class: "btn btn-link" %>
    <%= link_to 'Back', listings_path, class: "btn btn-link" %>
    

    在模特中,

    class Listing < ActiveRecord::Base
      has_attached_file :image, :styles => { :medium => "200x", :thumb =>        "100x100>" }, :default_url => "default.jpg"
      validates_attachment_content_type :image, :content_type => /\Aimage\/.*\Z/
    end
    

    在视图中,show.html.erb

    <p id="notice"><%= notice %></p>
    
    <div class="row">
       <div class="col-md-6">
         <div class="thumbnail">
          <%= image_tag @listing.image.url %>
        </div>
      </div>
      <div class="col-md-6">
        <h3><%= @listing.name %></h3>
        <p><%= number_to_currency (@listing.price) %></p>
        <p><%= @listing.description %></p>
      </div>
    </div>
    
    <%= link_to 'Edit', edit_listing_path(@listing), class: "btn btn-link" %>
    <%= link_to 'Back', listings_path, class: "btn btn-link" %>
    

    安装了宝石,

    source 'https://rubygems.org'
    ruby "2.3.3"
    
    git_source(:github) do |repo_name|
      repo_name = "#{repo_name}/#{repo_name}" unless repo_name.include?("/")
      "https://github.com/#{repo_name}.git"
    end
    gem 'rails', '~> 5.0.1'
    gem 'puma', '~> 3.0'
    gem 'sass-rails', '~> 5.0'
    gem 'uglifier', '>= 1.3.0'
    gem 'coffee-rails', '~> 4.2'
    gem 'jquery-rails'
    gem 'turbolinks', '~> 5'
    gem 'jbuilder', '~> 2.5'
    gem 'bootstrap-sass', '~> 3.3.6'
    gem "paperclip", git: "git://github.com/thoughtbot/paperclip.git"
    gem 'listen', '~> 3.1.5'
    gem 'aws-sdk'
    
    group :production do
      gem 'pg'
      gem 'rails_12factor'
    end
    
    group :development, :test do
      gem 'sqlite3'
    end
    
    group :doc do
      gem 'sdoc', require: false
    end
    
    终端内的

    错误,

    Listing Load (5.7ms)  SELECT  "listings".* FROM "listings" WHERE      "listings"."id" = ? LIMIT ?  [["id", 1], ["LIMIT", 1]]
       (0.1ms)  begin transaction
    [paperclip] Trying to link   /var/folders/__/2162ls5577704gd514y0859w0000gp/T/RackMultipart20170210-    36927-1iuewku.jpg to  /var/folders/__/2162ls5577704gd514y0859w0000gp/T/c3e768b17c5aa48db8ffbc959904bbaa20170210-36927-1ywsn2q.jpg
    

    [纸夹]试图链接/var/folders//2162ls5577704gd514y0859w0000gp/T/c3e768b17c5aa48db8ffbc959904bbaa20170210-36927-1ywsn2q.jpg到/ var /文件夹/ / 2162ls5577704gd514y0859w0000gp / T / c3e768b17c5aa48db8ffbc959904bbaa20170210-36927-1t9j57i。 JPG     Command :: file -b --mime&#39; / var / folders / /2162ls5577704gd514y0859w0000gp/T/c3e768b17c5aa48db8ffbc959904bbaa20170210-36927-1t9j57i.jpg' Command :: identify -format&#39;%wx%h,%[exif:orientation]&#39; &#39;在/ var /文件夹/ /2162ls5577704gd514y0859w0000gp/T/c3e768b17c5aa48db8ffbc959904bbaa20170210-36927-1ywsn2q.jpg [0]&#39; 2 - ;的/ dev / null的 Command :: identify -format%m&#39; / var / folders / /2162ls5577704gd514y0859w0000gp/T/c3e768b17c5aa48db8ffbc959904bbaa20170210-36927-1ywsn2q.jpg [0]&#39;     Command :: convert&#39; / var / folders / /2162ls5577704gd514y0859w0000gp/T/c3e768b17c5aa48db8ffbc959904bbaa20170210-36927-1ywsn2q.jpg [0]&#39; -auto-orient -resize&#34; 200&#34; &#39;在/ var /文件夹/的 / 2162ls5577704gd514y0859w0000gp / T / 73570fb1d3ecfa0dc9a9d5e124c5763420170210-36927-j452kb&#39;     [纸夹]试图链接的/ var /文件夹/ / 2162ls5577704gd514y0859w0000gp / T / 73570fb1d3ecfa0dc9a9d5e124 c5763420170210-36927-j452kb到/ var /文件夹/的 / 2162ls5577704gd514y0859w0000gp / T / 9918700e8a5840d631b32dff0efdc32820170210-36927-1j9zu6h     Command :: identify -format&#39;%wx%h,%[exif:orientation]&#39; &#39;在/ var /文件夹/ /2162ls5577704gd514y0859w0000gp/T/c3e768b17c5aa48db8ffbc959904bbaa20170210-36927-1ywsn2q.jpg [0]&#39; 2 - ;的/ dev / null的 Command :: identify -format%m&#39; / var / folders / /2162ls5577704gd514y0859w0000gp/T/c3e768b17c5aa48db8ffbc959904bbaa20170210-36927-1ywsn2q.jpg [0]&#39;     Command :: convert&#39; / var / folders / /2162ls5577704gd514y0859w0000gp/T/c3e768b17c5aa48db8ffbc959904bbaa20170210-36927-1ywsn2q.jpg [0]&#39; -auto-orient -resize&#34; 100x100&gt;&#34; &#39;在/ var /文件夹/的 / 2162ls5577704gd514y0859w0000gp / T / 73570fb1d3ecfa0dc9a9d5e124c5763420170210-36927-1t64b8q&#39;     [纸夹]试图链接的/ var /文件夹/ / 2162ls5577704gd514y0859w0000gp / T / 73570fb1d3ecfa0dc9a9d5e124c5763420170210-36927-1t64b8q到/ var /文件夹/的 / 2162ls5577704gd514y0859w0000gp / T / 5a42e5f066b94471d8d7dd70241f775820170210-36927-1l2vm2j     [纸夹]试图/var/folders//2162ls5577704gd514y0859w0000gp/T/c3e768b17c5aa48db8ffbc959904bbaa20170210-36927-1ywsn2q.jpg链接到/var/folders//2162ls5577704gd514y0859w0000gp/T/c3e768b17c5aa48db8ffbc959904bbaa20170210-36927-h40oj7.jpg Command :: file -b --mime&#39; / var / folders / /2162ls5577704gd514y0859w0000gp/T/c3e768b17c5aa48db8ffbc959904bbaa20170210-36927-h40oj7.jpg'     SQL(0.9ms)UPDATE&#34; listing&#34; SET&#34; image_file_name&#34; =?,&#34; image_file_size&#34; =?,&#34; image_updated_at&#34; =?,&#34; updated_at&#34; =?在哪里&#34;列表&#34;。&#34; id&#34; =? [[&#34; image_file_name&#34;,&#34; 022916_flyMG2.jpg&#34;],[&#34; image_file_size&#34;,12403],[&#34; image_updated_at&#34;,2017-02- 10 01:24:57 UTC],[&#34; updated_at&#34;,2017-02-10 01:24:58 UTC],[&#34; id&#34;,1]](1.0ms)回滚交易     在457ms内完成500内部服务器错误(ActiveRecord:8.6ms)

    Errno::EACCES (Permission denied @ dir_s_mkdir - /listings):
    
    app/controllers/listings_controller.rb:44:in `block in update'
    app/controllers/listings_controller.rb:43:in `update'
      Rendering /Users/chrisdionne/.rvm/gems/ruby-2.3.3/gems/actionpack-  5.0.1/lib/action_dispatch/middleware/templates/rescues/diagnostics.html.erbwithin rescues/layout
      Rendering /Users/chrisdionne/.rvm/gems/ruby-2.3.3/gems/actionpack- 5.0.1/lib/action_dispatch/middleware/templates/rescues/_source.html.erb
      Rendered /Users/chrisdionne/.rvm/gems/ruby-2.3.3/gems/actionpack-5.0.1/lib/action_dispatch/middleware/templates/rescues/_source.html.erb (7.4ms)
      Rendering /Users/chrisdionne/.rvm/gems/ruby-2.3.3/gems/actionpack-5.0.1/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb
      Rendered /Users/chrisdionne/.rvm/gems/ruby-2.3.3/gems/actionpack-5.0.1/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb (3.6ms)
      Rendering /Users/chrisdionne/.rvm/gems/ruby-2.3.3/gems/actionpack-5.0.1/lib/action_dispatch/middleware/templates/rescues/_request_and_response.html.erb
      Rendered /Users/chrisdionne/.rvm/gems/ruby-2.3.3/gems/actionpack-5.0.1/lib/action_dispatch/middleware/templates/rescues/_request_and_response.html.erb (3.5ms)
      Rendered /Users/chrisdionne/.rvm/gems/ruby-2.3.3/gems/actionpack-5.0.1/lib/action_dispatch/middleware/templates/rescues/diagnostics.html.erb within rescues/layout (152.5ms)
    

1 个答案:

答案 0 :(得分:1)

正如@tadman所说,您正试图在应用程序路径之外创建附件。

尝试更改

Paperclip::Attachment.default_options[:path] = '/:class/:attachment/:id_partition/:style/:filename'

类似

Paperclip::Attachment.default_options[:path] = ':rails_root/public/system/:class/:attachment/:id_partition/:style/:filename'

Paperclip::Attachment.default_options[:path] = "#{Rails.root}/public/system/:class/:attachment/:id_partition/:style/:filename"