У меня проблема с очисткой / удалением изображений после их загрузки через Active Storage. Я пытался следовать инструкциям, и я все еще получаю ту же ошибку. Ошибка описывается в командной строке как Ошибка шаблона :: Ошибка (неопределенный метод 'stringify_keys' для ....
Любое предложение было бы замечательно
Командная строка
ActionView::Template::Error (undefined method `stringify_keys' for "http://localhost:3000/jobs/21/delete_image_attachment":String):
11: <div class="panel-body">
12: <span class="pull-right">
13: <%=
14: link_to 'Remove', delete_image_attachment_job_url(@job.images[image]),
15: remote: true,
16: method: :delete,
17: data: {confirm: "Are you sure"} do %>
app/views/jobs/_photos_list.html.erb:14:in `block in _app_views_jobs__photos_list_html_erb__192211306_83310024'
app/views/jobs/_photos_list.html.erb:5:in `_app_views_jobs__photos_list_html_erb__192211306_83310024'
app/views/jobs/photo_upload.html.erb:51:in `_app_views_jobs_photo_upload_html_erb___795227943_83576688'
Моя модель
class Job < ApplicationRecord
belongs_to :user
has_many_attached :images
validates :job_category, presence: true
validates :job_type, presence: true
validates :recurrence, presence: true
#validates :job_title, presence: true
#validates :job_description, presence: true
end
Контроллер
class JobsController < ApplicationController
before_action :set_job , except: [:index, :new, :create, :edit]
before_action :authenticate_user!, except: [:show]
before_action :is_authorised, only: [:listing, :budget, :description, :photo_upload, :location, :update, :show, :delete ]
def delete_image_attachment
@images = ActiveStorage::Attachment.find(params[:id])
@images.purge
redirect_back(fallback_location: request.referer)
end
Вид
<% if @job.images.attached? %>
<br/>
<div class="row">
<% (0...@job.images.count).each do |image| %>
<div class="col-md-4">
<div class="panel panel-default">
<div class="panel-heading preview">
<%= image_tag(@job.images[image]) %>
</div>
<div class="panel-body">
<span class="pull-right">
<%=
link_to 'Remove', delete_image_attachment_job_url(@job.images[image]),
remote: true,
method: :delete,
data: {confirm: "Are you sure"} do %>
<i class="fa fa-trash-o" aria-hidden="true"></i>
<% end %>
</span>
</div>
</div>
</div>
<% end %>
</div>
<% end %>
Мои маршруты
Rails.application.routes.draw do
root 'pages#home'
resources :jobs_devs
resources :jobs
resources :jobs_devs, except: [:placeholder] do
member do
get 'listing'
get 'budget'
get 'description'
get 'photo_upload'
get 'featured'
get 'location'
get 'update'
get 'premium'
get 'show'
delete :delete_image_attachment
end
end
devise_for :users,
:path => '',
:path_names => {:sign_in => 'login', :sign_out => 'logout', :edit => 'profile', :sign_up => 'registration'},
:controllers => {:omniauth_callbacks => 'omniauth_callbacks', :registrations => 'registrations' }
resources :users, only: [:show]
resources :jobs, except: [:edit] do
member do
get 'listing'
get 'budget'
get 'description'
get 'photo_upload'
get 'featured'
get 'location'
get 'update'
get 'premium'
get 'show'
delete :delete_image_attachment
end
end
end