Хорошо, вы поняли суть моей проблемы в названии. Я создал приложение в рельсах, которое требует, чтобы пользователи создали профиль и загрузили изображение, чтобы получить доступ к некоторым функциям. Во всяком случае, все работает, кроме части загрузки изображений.
Я новичок во всем этом, и я немного запутался, в частности, с Devise. Я ищу пользовательский контроллер, где я должен найти действие создания для пользователей, верно? Но я понятия не имею, где его найти.
При этом я даже не уверен, что проблема связана с контроллером. Может ли источник проблемы быть простой формой? Без понятия. Я долго искал и пытался, и я подумал, что пришло время спросить сообщество:)
Я собираюсь поделиться всем, что я могу придумать, что касается проблемы. Дайте мне знать, если вам нужно, чтобы я показал что-то еще.
1 / Модель пользователя:
class User < ApplicationRecord
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable, :trackable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :validatable
has_many :user_instruments, dependent: :destroy
has_many :instruments, through: :user_instruments
has_many :messages, dependent: :destroy
has_one_attached :photo, dependent: :destroy
has_many :reviews_written, class_name: "Review", foreign_key: :writer_id
has_many :reviews_received, class_name: "Review", foreign_key: :receiver_id
has_many :jam_sessions, dependent: :destroy
def profile_picture
if photo.attached?
photo.key
else
"avatar-unknown.png"
end
end
def full_name
"#{first_name} #{last_name}"
end
end
2 / Контроллер приложения:
class ApplicationController < ActionController::Base
before_action :authenticate_user!, except: [:home, :index, :show]
before_action :configure_permitted_parameters, if: :devise_controller?
def configure_permitted_parameters
# For additional fields in app/views/devise/registrations/new.html.erb
devise_parameter_sanitizer.permit(:sign_up, keys: [:first_name, :last_name, :bio])
# For additional in app/views/devise/registrations/edit.html.erb
devise_parameter_sanitizer.permit(:account_update, keys: [:username])
end
def default_url_options
{ host: ENV["DOMAIN"] || "localhost:3000" }
end
end
3 / Новый Посмотрите, где находится простая форма:
<div class="container h-100">
<div class="row justify-content-center align-items-center mt-3">
<div class="col col-5">
<h2>Sign up</h2>
<%= simple_form_for(resource, as: resource_name, url: registration_path(resource_name)) do |f| %>
<%= f.error_notification %>
<div class="form-inputs">
<%= f.input :email,
required: true,
autofocus: true,
input_html: { autocomplete: "email" }%>
<%= f.input :password,
required: true,
hint: ("#{@minimum_password_length} characters minimum" if @minimum_password_length),
input_html: { autocomplete: "new-password" } %>
<%= f.input :password_confirmation,
required: true,
input_html: { autocomplete: "new-password" } %>
<%= f.input :first_name,
required: true %>
<%= f.input :last_name,
required: true %>
<%= f.input :bio,
required: true %>
<%= f.input :photo, as: :file %>
<%= cl_image_upload_tag(:image_id) %>
</div>
<div class="d-flex justify-content-end">
<%= f.button :submit, "Sign up", class: 'big-button block' %>
</div>
<% end %>
<div class="mt-3 mb-3">
<%= render "devise/shared/links" %>
</div>
</div>
</div>
</div>
Как вы можете видеть, есть две разные строки, чтобы предложить пользователю загрузить изображение. Кажется, что они оба работают с точки зрения пользователя, но на самом деле никогда не загружают ни одного изображения в мой облачный каталог.
4 / У меня есть эта строка и в моем файле development.rb, и в файле production.rb:
config.active_storage.service = :cloudinary
5 / Я добавил эту строку в config / storage.yml
cloudinary:
service: Cloudinary
6 / И я выполнил необходимые шаги в моем терминале для настройки cloudinary для моей герои:
heroku config: set CLOUDINARY_URL = cloudinary: //166....
Я что-то упустил?
Любая помощь будет очень признательна! Оливье