【问题标题】:Paper Clip - No route matches [GET]回形针 - 没有路线匹配 [GET]
【发布时间】:2015-08-16 11:58:30
【问题描述】:

我有一个可以编辑作者的视图,当我选择照片并单击更新按钮时,我可以为该作者选择一张照片,我收到一条错误消息:

ActionController::RoutingError (没有路由匹配 [GET] "/photos/original/missing.png"):

private
    def author_params
        params.require(:author).permit(:name, :photo)
    end

路线

 resources :quotes, only: [:index, :edit, :create, :destroy, :update]
 resources :authors, only: [:index, :show, :destroy, :edit, :update]

照片所在的作者模型

has_many :quotes
has_attached_file :photo
validates_attachment_content_type :photo, :content_type => ["photo/jpg", "photo/png", "photo/jpeg"]

查看

<%= form_for @author, html: {multipart: true},method: :patch do |f| %>
<p>
    <%= f.label :name %>
    <%= f.text_field :name %>
</p>
<p>
    <%= f.label :photo %>
    <%= f.file_field :photo %>
</p>
<p>
    <%= f.submit "Edit Author"%>
</p>
<% end %>

编辑

引用创建它的作者的控制器

def create
    @author = Author.where(name: params[:name]).first_or_create
    @quote = Quote.new(quote_params)
    @quote.author = @author
    @quote.save
    redirect_to quotes_path
end

所以作者在创建时只有名字

【问题讨论】:

  • 您的Author 模型的代码是否比您发布的更多?

标签: ruby-on-rails paperclip


【解决方案1】:

我找到了答案。 问题出在这条线上。

这个:

validates_attachment_content_type :photo, :content_type => ["photo/jpg", "photo/png", "photo/jpeg"]

应该是:

validates_attachment_content_type :photo, :content_type => ["image/jpg", "image/png", "image/jpeg"]

【讨论】:

    猜你喜欢
    • 2012-09-15
    • 1970-01-01
    • 1970-01-01
    • 2016-06-15
    • 2011-12-11
    • 2015-09-27
    • 2015-10-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多