好的,在标题中您会明白我的问题。我在rails中创建了一个应用程序,该应用程序要求用户创建配置文件并上传图片才能访问某些功能。 无论如何,除了图片上传部分之外,其他所有东西都可以正常工作。
我不熟悉这一切,尤其对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,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,hint: ("#{@minimum_password_length} characters minimum" if @minimum_password_length),input_html: { autocomplete: "new-password" } %>
<%= f.input :password_confirmation,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>
如您所见,有2条不同的行提示用户上传图片。他们俩似乎都可以从用户的角度进行工作,但是实际上从来没有将任何图片上传到我的云服务器。
4 /我的development.rb和production.rb文件中都有这一行:
config.active_storage.service = :cloudinary
5 /我在config / storage.yml中添加了这一行
cloudinary:
service: Cloudinary
6 /并且我在终端中执行了必要的步骤以将cloudinary配置为我的heroku:
heroku config:set CLOUDINARY_URL = cloudinary:// 166 ....
我想念什么吗?
非常感谢任何人的帮助! 奥利维尔