No route matches [GET] for Pinned Image

孤者浪人 提交于 2020-01-05 08:59:11

问题


When the current_user clicks the pin how can that image be saved to the current_user?

Button:

  <%= 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 %>

Outputs:

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,

The id is different for the pinned image giving the error: No route matches [GET] "/system/inspirations/images/000/000/002/medium/choose-optimism.png"

The working image has 001:

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

What's the best way to fix this so I can continue to pass different IDs, but use the same image?

controller

@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:


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

In your model:

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

However, after you do this, you'll have to recreate your first Inspiration so it will use new URL interpolation.



来源:https://stackoverflow.com/questions/40543234/no-route-matches-get-for-pinned-image

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!