【问题标题】:No route matches [GET] for Pinned Image固定图像没有路线匹配 [GET]
【发布时间】:2016-11-11 07:35:39
【问题描述】:

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

【问题讨论】:

  • 你能发布你的控制器动作的代码吗?
  • @MuradYusufov 完成!
  • 我认为你需要定义一个自定义插值。等一下,我试着写一个答案

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


【解决方案1】:

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

在您的模型中:

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

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

【讨论】:

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