2014-07-30 3 views
0

레일 4, devise gem 및 paperclip gem을 사용하고 있습니다. 내 응용 프로그램이 기본 URL을 사용하고 싶지 않습니다. 내 응용 프로그램을 내 데이터베이스에 기본 클립 클립 URL을 저장하려면 어떻게합니까?레일 4 종이 클립 기본 URL이 작동하지 않습니다.

내 앱에 :superstarbadge:avatar 클립의 기본값을 저장하도록 추가해야합니다. :superstarbadgef.hidden_field :superstarbadge과 함께 저장하고 싶습니다. 기본적으로 각 사용자별로 저장되기를 원하지만, 시도 할 때 no handler found for "/images/superbadge.jpeg" 오류가 발생했습니다.

그래서 두 가지 질문이

, 여기 f.hidden_field :superstarbadge

와 함께 데이터베이스에 기본 클립 URL을 저장하는 방법 f.file_field :avatar
2와 함께 데이터베이스에 기본 클립 URL을 저장하는 방법
1. 내 컨트롤러 :

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 
:

여기 내 사용자 모델의3210

내 유증 등록 양식 : 당신이 당신의 샘플 이미지를 저장 할

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
  1. ? (앱 루트의 전체 경로)
    1. 모든 사용자가 생성시 동일한 이미지를 수신하는 경우 숨겨진 필드를 사용하는 이유는 무엇입니까? 종이 클립은

이상한 일에 대한 no handler found for "/images/superbadge.jpeg" 아마 .JPG로 변경합니다 ... 기본 URL로 채울 것인가?

관련 문제