没有路线匹配固定图像的 [GET]
No route matches [GET] for Pinned Image
当 current_user
单击图钉时,如何将该图像保存到 current_user
?
按钮:
<%= 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
https://github.com/thoughtbot/paperclip/wiki/Interpolations
在您的模型中:
has_attached_file :image, url: '/system/inspirations/images/:style/:filename'
但是,执行此操作后,您必须重新创建第一个 Inspiration,以便它使用新的 URL 插值。
当 current_user
单击图钉时,如何将该图像保存到 current_user
?
按钮:
<%= 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
https://github.com/thoughtbot/paperclip/wiki/Interpolations
在您的模型中:
has_attached_file :image, url: '/system/inspirations/images/:style/:filename'
但是,执行此操作后,您必须重新创建第一个 Inspiration,以便它使用新的 URL 插值。