2016-02-09 7 views
4

Я пытаюсь подключить REFILE к моему мнению, и я получаю следующее сообщение об ошибке: enter image description hereREFILE simple_form не определен метод attachment_field

Вот мои модели:

class Job < ActiveRecord::Base 
    acts_as_paranoid 

    acts_as_taggable 
    acts_as_taggable_on :languages 

    belongs_to :company 
    belongs_to :category 

    validates :title, 
      :location, 
      :category, 
      :language_list, 
      :short_description, 
      :description, 
      :application_process, 
      presence: true 
end 

class Company < ActiveRecord::Base 
    acts_as_paranoid 
    has_many :jobs 

    attachment :company_logo, type: :image 

    validates :name, :url, :email, presence: true 
end 

И вид simple_form (игнорировать binding.pry)

= render layout: 'header' do 
    = simple_form_for(@job) do |j| 
    div[class='panel-heading'] 
     h3[class='panel-title'] 
     |Position Details 
    div[class='panel-body'] 
     = j.input :title 
     = j.input :location 
     = j.association :category, as: :radio_buttons 
     = j.input :language_list, as: :check_boxes, collection: @tags 
     = j.input :short_description 
     = j.input :description, input_html: { class: 'textarea-height wysihtml5' } 
     = j.input :application_process 
    div[class='panel-heading'] 
     h3[class='panel-title'] 
     |Company Details 
    div[class='panel-body'] 
     = j.simple_fields_for :company do |jc| 
     = jc.input :name 

     = binding.pry 

     = jc.input :company_logo, as: :attachment 
     = jc.input :url 
     = jc.input :email 
    div[class='panel-heading panel-heading-info'] 
     h3[class='panel-title'] 
     |Would you like your job posting featured? 
    div[class='panel-body'] 
     p 
     |Featured posted are promoted with additional design elements to grab the 
      job seeker's attention. This additional marketing capability can be purchased 
      for an additonal $#{AppConfig.product['settings']['job_base_featured_price']}. 

     = j.input :is_featured 

     = j.button :button, type: 'button', class: 'btn-primary' do 
     = job_posting_button_step_label 
     => 
     i[class='fa fa-arrow-circle-right'] 

в то время как я был разбор документации я не могу показаться, чтобы выяснить, почему attachment_field не определено.

Кроме того, у меня есть установка refile.rb инициализатора следующим образом:

require 'refile/rails' 
require 'refile/simple_form' 

Я интересно, если документы перепутались или simple_form кусок BORKED, потому что если я включаю это:

= jc.input :company_logo, as: :file, direct: true, presigned: true 

ответ

1

После долгой битвы вот как я разобрался в этой ситуации. Сначала я нашел это сообщение SO Styling file upload button for simple_form_for with Bootstrap in Rails 3, которое заставило меня попробовать https://github.com/jasny/bootstrap/. У Jasny есть несколько сладких файловых загрузчиков, но все драгоценные камни устарели. [Обратите внимание, я надеюсь исправить это с помощью патча, как у меня есть время на этой неделе], так что я скачал файлы Jasny к JavaScripts поставщика и таблицы стилей папки, как показано ниже:

enter image description here

Я также использовал https://rails-assets.org/ тянуть в holder.js в моей Gemfile:

source 'https://rails-assets.org' do 
    gem 'rails-assets-holderjs' 
end 

Далее, я обновил мой application.js файл со следующим:

//= require refile 
//= require holderjs 
//= require jasny-bootstrap 

Далее мне потребовалось стили в моей установке Sass:

// External Libraries Built For Bootstrap in Vendor 
@import 'awesome-bootstrap-checkbox'; 
@import 'jasny-bootstrap'; 

Это дало мне инструменты, чтобы изменить свой файл загрузчик в простой форме:

= j.simple_fields_for :company do |jc| 
    = jc.input :name 
    div 
    label 
     = t('simple_form.labels.company.logo') 
    div[class="form-group fileinput fileinput-new" data-provides="fileinput"] 
    div[class="fileinput-new thumbnail" style="width: 200px; height: 200px;"] 
     img[data-src="holder.js/200x200" alt="..."] 
    div[class="fileinput-preview fileinput-exists thumbnail" style="max-width: 200px; max-height: 200px;"] 
    div 
     span[class="btn btn-default btn-file"] 
     span[class="fileinput-new"] 
      |Select image 
     span[class="fileinput-exists"] 
      |Change 
     = jc.input_field :logo, direct: true, presigned: true 
     a[href="#" class="btn btn-default fileinput-exists" data-dismiss="fileinput"] 
     |Remove 
    p[class="help-block"] 
     = t('simple_form.hints.company.logo')  
    = jc.input :url 
    = jc.input :email 

что привело к довольно пользователю!

enter image description here

Я хотел бы реорганизовать это частичное, но я буду ждать, пока я не иметь другую форму для загрузки файла для решения этой проблемы. Кроме того, если вы посмотрите на вышеприведенный код, я следую стандарту locale, который использует simple_form. Не очень, но это работает.