Я тоже использую Devise. Я обновляю продавца, и изображение аватара не появляется на странице продавцов. Это происходит некоторое время.
Это вывод сервера в терминале:
Started GET "/farmers" for 127.0.0.1 at 2020-08-06 19:26:57 +0100
(0.5ms) SELECT sqlite_version(*)
Processing by UserController#farmers as HTML
Rendering user/farmers.html.erb within layouts/application
User Load (2.6ms) SELECT "users"."farm_name", "avatar", "users"."about_farm", "users"."farm_type", "users"."county" FROM "users" WHERE "users"."role" = ? [["role", 1]]
↳ app/views/user/farmers.html.erb:6
ActiveStorage::Attachment Load (2.1ms) SELECT "active_storage_attachments".* FROM "active_storage_attachments" WHERE "active_storage_attachments"."record_id" IS NULL AND "active_storage_attachments"."record_type"
= ? AND "active_storage_attachments"."name" = ? LIMIT ? [["record_type", "User"], ["name", "avatar"], ["LIMIT", 1]]
↳ app/views/user/farmers.html.erb:28
CACHE ActiveStorage::Attachment Load (0.1ms) SELECT "active_storage_attachments".* FROM "active_storage_attachments" WHERE "active_storage_attachments"."record_id" IS NULL AND "active_storage_attachments"."record_type" = ? AND "active_storage_attachments"."name" = ? LIMIT ? [["record_type", "User"], ["name", "avatar"], ["LIMIT", 1]]
↳ app/views/user/farmers.html.erb:28
Rendered user/farmers.html.erb within layouts/application (Duration: 848.9ms | Allocations: 13223)
[Webpacker] Everything's up-to-date. Nothing to do
User Load (1.2ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? ORDER BY "users"."id" ASC LIMIT ?
[["id", 18], ["LIMIT", 1]]
↳ app/views/layouts/application.html.erb:47
Rendered layouts/_search.html.erb (Duration: 1.3ms | Allocations: 173)
Completed 200 OK in 1297ms (Views: 1217.8ms | ActiveRecord: 30.9ms | Allocations: 21165)
Вот ссылка на код для страницы просмотра: https://gist.github.com/Josebuendia/21ba9b9a7e6b67bf593ed44675fbb97c
И контроллер, который выбирает данные: https://gist.github.com/Josebuendia/b22486363fdffe470b27b34daad2cc9b
user = User.last User Load (0.8ms) SELECT «users». * FROM "пользователи" ЗАКАЗАТЬ ПО "пользователям". "id" DES C LIMIT? [["LIMIT", 1]] => # irb (основной): 013: 0> user.avatar.attached? ActiveStorage :: Attachment Load (3,1 мс) ВЫБРАТЬ "active_storage_attachments". * FROM "active_storage_attachments" ГДЕ "active_storage_attachments". "Record_id" =? И "active_storage_attachments". "Record_type" =? И "active_storage_attachments". "Name" =? LIMIT? [["record_id", 18], ["record_type", "User"], ["name", "avatar"], ["LIMIT", 1]] => true irb (main): 014: 0>
ents "WHERE" active_storage_attachments "." Record_id "=? AND" active_storage_attachments "." Record_type "=? И" active_storage_attachments "." Name "=? LIMIT? [[" Record_id ", 18], [" record_type "," User "], [" name "," avatar "], [" LIMIT ", 1]] => true
Странно то, что данные извлекаются правильно с элементами, даже если это также использует гем Active Storage!
Элементы формы в форме элементов - это form.
В других формах для пользователей это f.
Хотя, я сомневаюсь, что имеет значение.
Код страницы просмотра:
<p id="notice"><%= notice %></p>
<div id="itemsContainer">
<h1>Our Farmers</h1>
<% @users.each do |user| %>
<div class="itemhols">
<%
=begin%>
<h1><%= user.email %></h1>
<%
=end%>
<!--Data to include on farmers: name, pic, about, type, county-->
<h2><%= user.farm_name %></h2>
<%
=begin%>
<p><%= image_tag user.farmers_picture if user.farmers_picture.present? %></p>
<%
=end%>
<%
=begin%>
<%= image_tag user.avatar.variant(resize: "200x200").processed if user.avatar.attached? %>
<%
=end%>
<% if user.avatar.attached? %>
<image src="<%=(url_for(user.avatar))%>" class="itemholsIm">
<% end %>
<p><%= user.about_farm %></p>
<p><%= user.farm_type %></p>
<p><%= user.county %></p>
<%
=begin%>
<%= link_to 'Show', user, :class => "button", :role => "button" %>
<%
=end%>
<%
=begin%>
<--<%= link_to 'Show', item, :class => "button", :role => "button" %>
<%
=end%>
</div>
<% end %>
</div>
И контроллер, который извлекает данные:
class UserController < ApplicationController
def login
session[:login] = 1
session[:cart] = nil
#Changed the line below to Seller Login sucessfull! from "Admin Login sucessfull!"
flash[:notice] = "Seller Login sucessfull!"
redirect_to :controller => :items
end
def logout
session[:login] = nil
session[:cart] = nil
flash[:notice] = "You have been successfully logged out!!"
redirect_to :controller => :items
end
#iteration for farmers page
def farmers
#@users = User.where(role: 1)
@users = User.select(:farm_name, :avatar, :about_farm, :farm_type, :county).where(role: 1)
end
def search
st = "%#{params[:q]}%"
@users = User.where("email like ?", st)
end
def show
end
#def farmers
# @user = User.find(params[:id])
# FIXME get the view working for the farmers page
#end
def upgrade_admin
@user.update_attribute(:adminrole, true)
redirect_to :action => :admin_users
end
def downgrade_admin
@user.update_attribute(:adminrole, false)
redirect_to :action => :admin_users
end
end