Skip to content

Instantly share code, notes, and snippets.

@suras
Created July 8, 2013 13:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save suras/5948782 to your computer and use it in GitHub Desktop.
Save suras/5948782 to your computer and use it in GitHub Desktop.
rails gem paperclip problem model.attachment_definitions problem
rails_admin paperclip error rails 4.0/ruby 2.0 paperclip- 3.4.2 rails_admin -0.5.0
model.attachment_definitions attachment definitions undefined in paperclip.rb
/home/surendar/.rvm/gems/ruby-2.0.0-p0@ruby2/gems/activerecord-4.0.0/lib/active_record/dynamic_matchers.rb:22
:in `method_missing': undefined method `attachment_definitions' for #<Class:0xa332868> (NoMethodError)
from /home/surendar/www/cvBuilder/config/initializers/rails_admin.rb:40:in `block in <module:Fields>'
from /home/surendar/.rvm/gems/ruby-2.0.0-p0@ruby2/bundler/gems/rails_admin-fef978f2c5dc/lib/rails_adm
in/config/fields.rb:54:in `call'
from /home/surendar/.rvm/gems/ruby-2.0.0-p0@ruby2/bundler/gems/rails_admin-fef978f2c5dc/lib/rails_adm
in/config/fields.rb:54:in `block (2 levels) in factory'
from /home/surendar/.rvm/gems/ruby-2.0.0-p0@ruby2/bundler/gems/rails_admin-fef978f2c5dc/lib/rails_adm
in/config/fields.rb:54:in `each'
from /home/surendar/.rvm/gems/ruby-2.0.0-p0@ruby2/bundler/gems/rails_admin-fef978f2c5dc/lib/rails_adm
in/config/fields.rb:54:in `find'
from /home/surendar/.rvm/gems/ruby-2.0.0-p0@ruby2/bundler/gems/rails_admin-fef978f2c5dc/lib/rails_adm
in/config/fields.rb:54:in `block in factory'
from /home/surendar/.rvm/gems/ruby-2.0.0-p0@ruby2/bundler/gems/rails_admin-fef978f2c5dc/lib/rails_adm
in/config/fields.rb:50:in `each'
from /home/surendar/.rvm/gems/ruby-2.0.0-p0@ruby2/bundler/gems/rails_admin-fef978f2c5dc/lib/rails_adm
in/config/fields.rb:50:in `factory'
from /home/surendar/.rvm/gems/ruby-2.0.0-p0@ruby2/bundler/gems/rails_admin-fef978f2c5dc/lib/rails_adm
in/config/has_fields.rb:130:in `_fields'
from /home/surendar/.rvm/gems/ruby-2.0.0-p0@ruby2/bundler/gems/rails_admin-fef978f2c5dc/lib/rails_adm
in/config/has_fields.rb:128:in `_fields'
from /home/surendar/.rvm/gems/ruby-2.0.0-p0@ruby2/bundler/gems/rails_admin-fef978f2c5dc/lib/rails_adm
in/config/has_fields.rb:108:in `all_fields'
from /home/surendar/.rvm/gems/ruby-2.0.0-p0@ruby2/bundler/gems/rails_admin-fef978f2c5dc/lib/rails_adm
in/config/has_fields.rb:83:in `fields'
from (erb):64:in `block in template'
from (erb):53:in `map'
from (erb):53:in `template'
from /home/surendar/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/2.0.0/erb.rb:849:in `eval'
from /home/surendar/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/2.0.0/erb.rb:849:in `result'
from /home/surendar/.rvm/gems/ruby-2.0.0-p0@ruby2/gems/thor-0.18.1/lib/thor/actions/file_manipulation
.rb:117:in `block in template'
from /home/surendar/.rvm/gems/ruby-2.0.0-p0@ruby2/gems/thor-0.18.1/lib/thor/actions/create_file.rb:54
:in `call'
from /home/surendar/.rvm/gems/ruby-2.0.0-p0@ruby2/gems/thor-0.18.1/lib/thor/actions/create_file.rb:54
:in `render'
from /home/surendar/.rvm/gems/ruby-2.0.0-p0@ruby2/gems/thor-0.18.1/lib/thor/actions/create_file.rb:47
:in `identical?'
from /home/surendar/.rvm/gems/ruby-2.0.0-p0@ruby2/gems/thor-0.18.1/lib/thor/actions/create_file.rb:73
:in `on_conflict_behavior'
from /home/surendar/.rvm/gems/ruby-2.0.0-p0@ruby2/gems/thor-0.18.1/lib/thor/actions/empty_directory.r
b:114:in `invoke_with_conflict_check'
from /home/surendar/.rvm/gems/ruby-2.0.0-p0@ruby2/gems/thor-0.18.1/lib/thor/actions/create_file.rb:61
:in `invoke!'
from /home/surendar/.rvm/gems/ruby-2.0.0-p0@ruby2/gems/thor-0.18.1/lib/thor/actions.rb:95:in `action'
from /home/surendar/.rvm/gems/ruby-2.0.0-p0@ruby2/gems/thor-0.18.1/lib/thor/actions/create_file.rb:26
:in `create_file'
from /home/surendar/.rvm/gems/ruby-2.0.0-p0@ruby2/gems/thor-0.18.1/lib/thor/actions/file_manipulation
.rb:116:in `template'
from /home/surendar/.rvm/gems/ruby-2.0.0-p0@ruby2/bundler/gems/rails_admin-fef978f2c5dc/lib/generator
s/rails_admin/install_generator.rb:78:in `install'
from /home/surendar/.rvm/gems/ruby-2.0.0-p0@ruby2/gems/thor-0.18.1/lib/thor/command.rb:27:in `run'
from /home/surendar/.rvm/gems/ruby-2.0.0-p0@ruby2/gems/thor-0.18.1/lib/thor/invocation.rb:120:in `inv
oke_command'
from /home/surendar/.rvm/gems/ruby-2.0.0-p0@ruby2/gems/thor-0.18.1/lib/thor/invocation.rb:127:in `blo
ck in invoke_all'
from /home/surendar/.rvm/gems/ruby-2.0.0-p0@ruby2/gems/thor-0.18.1/lib/thor/invocation.rb:127:in `eac
h'
from /home/surendar/.rvm/gems/ruby-2.0.0-p0@ruby2/gems/thor-0.18.1/lib/thor/invocation.rb:127:in `map
'
from /home/surendar/.rvm/gems/ruby-2.0.0-p0@ruby2/gems/thor-0.18.1/lib/thor/invocation.rb:127:in `inv
oke_all'
from /home/surendar/.rvm/gems/ruby-2.0.0-p0@ruby2/gems/thor-0.18.1/lib/thor/group.rb:233:in `dispatch
'
from /home/surendar/.rvm/gems/ruby-2.0.0-p0@ruby2/gems/thor-0.18.1/lib/thor/base.rb:439:in `start'
from /home/surendar/.rvm/gems/ruby-2.0.0-p0@ruby2/gems/railties-4.0.0/lib/rails/generators.rb:156:in
`invoke'
from /home/surendar/.rvm/gems/ruby-2.0.0-p0@ruby2/gems/railties-4.0.0/lib/rails/commands/generate.rb:
11:in `<top (required)>'
from /home/surendar/.rvm/gems/ruby-2.0.0-p0@ruby2/gems/activesupport-4.0.0/lib/active_support/depende
ncies.rb:228:in `require'
from /home/surendar/.rvm/gems/ruby-2.0.0-p0@ruby2/gems/activesupport-4.0.0/lib/active_support/depende
ncies.rb:228:in `block in require'
from /home/surendar/.rvm/gems/ruby-2.0.0-p0@ruby2/gems/activesupport-4.0.0/lib/active_support/depende
ncies.rb:213:in `load_dependency'
from /home/surendar/.rvm/gems/ruby-2.0.0-p0@ruby2/gems/activesupport-4.0.0/lib/active_support/depende
ncies.rb:228:in `require'
from /home/surendar/.rvm/gems/ruby-2.0.0-p0@ruby2/gems/railties-4.0.0/lib/rails/commands.rb:49:in `<t
op (required)>'
from bin/rails:4:in `require'
from bin/rails:4:in `<main>'
require 'rails_admin/config/fields'
require 'rails_admin/config/fields/types'
require 'rails_admin/config/fields/types/file_upload'
RailsAdmin::Config::Fields.register_factory do |parent, properties, fields|
extensions = [:file_name, :content_type, :file_size, :updated_at]
model = parent.abstract_model.model
if (properties[:name].to_s =~ /^(.+)_file_name$/) and defined?(::Paperclip) and model.attachment_definitions and model.attachment_definitions.has_key?(attachment_name = $1.to_sym)
field = RailsAdmin::Config::Fields::Types.load(:paperclip).new(parent, attachment_name, properties)
children_fields = []
extensions.each do |ext|
children_column_name = "#{attachment_name}_#{ext}".to_sym
if child_properties = parent.abstract_model.properties.find {|p| p[:name].to_s == children_column_name.to_s }
children_field = fields.find{ |f| f.name == children_column_name } || RailsAdmin::Config::Fields.default_factory.call(parent, child_properties, fields)
children_field.hide
children_field.filterable(false)
children_fields << children_field.name
end
end
field.children_fields(children_fields)
fields << field
true
else
false
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment