没有路线匹配固定图像的[GET]

时间:2016-11-11 07:35:40

标签: ruby-on-rails ruby image routes paperclip

current_user点击该图钉时,该图像如何保存到current_user

enter image description here

按钮:

  <%= simple_form_for(@inspiration) do |f| %>
    <%= f.hidden_field :image_file_name, value: inspiration.image_file_name %>
    <%= f.hidden_field :image_content_type, value: inspiration.image_content_type %>
    <%= f.hidden_field :image_file_size, value: inspiration.image_file_size %>
    <%= button_tag(type: 'submit', class: "btn btn-primary") do %>
      <span class="glyphicon glyphicon-pushpin"></span>
    <% end %>
  <% end %>

输出

pry(main)> Inspiration.first
 id: 1,
 user_id: 1,
 image_file_name: "choose-optimism.png",
 image_content_type: "image/png",
 image_file_size: 230082,
pry(main)> Inspiration.last
 id: 2, # Creating the issue of the route error & image not rendering
 user_id: 2,
 image_file_name: "choose-optimism.png",
 image_content_type: "image/png",
 image_file_size: 230082,

id对于产生错误的固定图片有所不同:No route matches [GET] "/system/inspirations/images/000/000/002/medium/choose-optimism.png"

工作图片有001

/system/inspirations/images/000/000/001/medium/choose-optimism.png?1478840469

解决此问题的最佳方法是什么,以便我可以继续传递不同的ID,但使用相同的图像?

控制器

@inspirations = @user.inspirations # Renders Images with Pin Overlayed
@inspiration = current_user.inspirations.build # For the Button

def create
  @inspiration = current_user.inspirations.build(inspiration_params)
  @inspiration.save
  respond_modal_with @inspiration
end

1 个答案:

答案 0 :(得分:1)

https://github.com/thoughtbot/paperclip/wiki/Interpolations

在你的模特中:

has_attached_file :image, url: '/system/inspirations/images/:style/:filename'

但是,执行此操作后,您必须重新创建第一个灵感,以便使用新的URL插值。