我使用Rails 4,设计gem和paperclip gem,我的应用程序不想使用默认URL,如何让我的应用程序将默认回形针url保存到我的数据库中?
我必须补充一点,我希望我的应用为:superstarbadge
和:avatar
回形针保存默认值。我希望我的:superstarbadge
与f.hidden_field :superstarbadge
一起保存,我希望默认情况下为每个用户保存,但是当我尝试这样做时,我遇到no handler found for "/images/superbadge.jpeg"
错误。
所以我有两个问题,
1。如何使用f.file_field :avatar
将默认回形针网址保存到数据库
2。如何使用f.hidden_field :superstarbadge
这是我的控制人员:
class ApplicationController < ActionController::Base
# Prevent CSRF attacks by raising an exception.
# For APIs, you may want to use :null_session instead.
protect_from_forgery with: :exception
before_action :configure_devise_permitted_parameters, if: :devise_controller?
protected
def configure_devise_permitted_parameters
registration_params = [:name, :email, :password, :password_confirmation,:avatar,:superstarbadge]
if params[:action] == "update"
devise_parameter_sanitizer.for(:account_update) {
|u| u.permit(registration_params << :current_password)
}
elsif params[:action] == "create"
devise_parameter_sanitizer.for(:sign_up) {
|u| u.permit(registration_params)
}
end
end
end
这是我的用户模型:
class User < ActiveRecord::Base
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable, :omniauthable
# :recoverable, :rememberable and :trackable
devise :database_authenticatable, :registerable, :validatable
has_attached_file :avatar, :styles => { :small => "100x100>" }, :default_url => "/images/one.jpg"
validates_attachment_content_type :avatar, :content_type => /\Aimage\/.*\Z/
has_attached_file :superstarbadge, :styles => { :small => "100x100>" }, :default_url => "/images/superbadge.jpeg"
validates_attachment_content_type :superstarbadge, :content_type => /\Aimage\/.*\Z/
has_many :questions
has_many :answers
def to_s
email
end
end
我的设计注册表:
h1 Sign up
= form_for(resource, as: resource_name, url: registration_path(resource_name), :html => { :multipart => true }) do |f|
= devise_error_messages!
.field
label= f.label :name
= f.text_field :name, autofocus: true
.field
label= f.label :email
= f.email_field :email, autofocus: true
.field
label= f.label :password
= f.password_field :password, autocomplete: 'off'
.field
label= f.label :password_confirmation
= f.password_field :password_confirmation, autocomplete: 'off'
.field
= f.label :avatar
= f.file_field :avatar
.field
= f.hidden_field :superstarbadge
div
= f.submit "Sign up"
答案 0 :(得分:0)
关于no handler found for "/images/superbadge.jpeg"
的奇怪之处可能会尝试将其更改为.jpg?