回形针 - 没有路线匹配 [GET]
Paper Clip - No route matches [GET]
我有一个可以编辑作者的视图,当我选择照片并单击更新按钮时,我可以为该作者选择一张照片我收到一条错误消息:
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
所以作者在创建时只有名字
我找到了答案。
问题出在这条线上。
这个:
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"]
我有一个可以编辑作者的视图,当我选择照片并单击更新按钮时,我可以为该作者选择一张照片我收到一条错误消息:
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
所以作者在创建时只有名字
我找到了答案。 问题出在这条线上。
这个:
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"]