I'm upgrading an app from Rails 3.1 to 3.2 and I'm getting:
NoMethodError (undefined method `write_inheritable_attribute' for #<Class:0x0000010a190dd8>):
app/models/test_file.rb:37:in `<class:TestFile>'
app/models/test_file.rb:1:in `<top (required)>'
app/models/ability.rb:44:in `initialize'
The error applies to this model code:
has_attached_file :logo,
:styles => {:medium => "300x200>", :thumb => "150x60>" },
:storage => :s3,
:s3_credentials => "#{::Rails.root.to_s}/config/s3.yml",
:path => "/logos/:style/:id/:filename"
I have no instances of write_inheritable_attribute anywhere in my app's code. If the above is removed, the error repeats for the next instance of similar code in the app (i.e. everywhere Paperclip is used).
# Gemfile
gem 'rmagick'
gem "paperclip", :git => "git://github.com/thoughtbot/paperclip.git"
I think this issue may be with Paperclip's internal code somewhere. Do you know what's going on here?
:s3_credentials => "#{Rails.root}/config/s3.yml",
Related
I'm running into a problem where everything in my test setup, including Spork's prefork block, is being reloaded and invoked on each run. It is taking 5-8 seconds for a test to fire off after guard picks up a change even though this is a new project so there are minimal tests and I even have an SSD.
Before I realized everything was reloading, I profiled it using the technique described by Jo Liss here and I've included those hanging requires but obviously that didn't help since it's all being reloaded anyway. However, that's when I noticed this:
Loaded Suite
test,test/controllers,test/controllers/manage,test/factories,test/functional/manage,test/helpers,test/helpers/manage,test/integration,test/models,test/support
I'm not seeing why it would reload everything. This is my first attempt at setting up minitest+spork+guard (i should have just gone with rspec, sigh) so I'm hoping it's something stupid. I'm including everything in hopes that someone has run into it or can easily spot what I've missed. Thanks in advance!
My files include:
test_helper.rb
require 'spork'
Spork.prefork do
#MiniTest::Rails.override_testunit!
ENV["RAILS_ENV"] = "test"
require File.expand_path('../../config/environment', __FILE__)
require 'guard'
require 'guard/interactors/readline'
require 'guard/ui'
require 'guard/interactors/coolline'
require 'guard/interactor'
require 'guard/dsl'
require 'guard/notifiers/rb_notifu'
require 'guard/notifier'
require 'guard/minitest/notifier'
require 'guard/minitest/runners/default_runner'
Dir[File.expand_path('test/support/*.rb')].each { |file| require file }
require "mocha"
Spork.trap_method(Rails::Application, :reload_routes!)
Spork.trap_method(Rails::Application::RoutesReloader, :reload!)
end
Guardfile
guard 'bundler' do
watch('Gemfile')
# Uncomment next line if Gemfile contain `gemspec' command
# watch(/^.+\.gemspec/)
end
guard 'spork', :wait => 65, :test_unit => false, :minitest => true, :minitest_env => { 'RAILS_ENV' => 'test' }, :bundler => true do
watch('config/application.rb')
watch('config/environment.rb')
watch(%r{^config/environments/.+\.rb$})
watch(%r{^config/initializers/.+\.rb$})
watch('Gemfile')
watch('Gemfile.lock')
watch('test/test_helper.rb') { "test" }
end
guard 'minitest' do
watch(%r|^test/test_helper\.rb|) { "test" }
watch(%r|^test/support/(.*)\.rb|) { "test" }
watch(%r{^test/.+_test\.rb$})
watch(%r|^app/models/(.*)\.rb|) {|m| ["test/models/#{m[1]}_test.rb", "test/integration/#{m[1]}_test.rb"] }
watch(%r|^app/controllers/(.*)\.rb|) {|m| ["test/controllers/#{m[1]}_test.rb", "test/integration/#{m[1]}_test.rb"] }
watch(%r|^app/views/(.*)\.html|) {|m| "test/integration/#{m[1]}_test.rb" }
watch(%r|^app/objects/(.*)\.rb|) {|m| "test/objects/#{m[1]}_object_test.rb" }
end
guard 'livereload' do
watch(%r{app/.+\.(erb|haml)})
watch(%r{app/helpers/.+\.rb})
watch(%r{(public/|app/assets).+\.(css|js|html)})
watch(%r{(app/assets/.+\.css)\.scss}) { |m| m[1] }
watch(%r{(app/assets/.+\.js)\.coffee}) { |m| m[1] }
watch(%r{config/locales/.+\.yml})
end
support/minitest.rb
#require "minitest/autorun"
require "minitest/rails"
require "minitest/spec"
require "minitest/pride"
require "minitest/rails/shoulda"
require "minitest/autorun"
require "capybara/rails"
class RequestSpec < MiniTest::Spec
include Rails.application.routes.url_helpers
include Capybara::DSL
include Rails.application.routes.url_helpers
end
MiniTest::Spec.register_spec_type /integration$/i, RequestSpec
#MiniTest::Spec.register_spec_type /object$/, MiniTest::Spec
class MiniTest::Rails::Controller
include Devise::TestHelpers
end
support/turn.rb
require 'turn'
require 'turn/autorun'
require 'turn/colorize'
require 'turn/reporter'
require 'turn/reporters/pretty_reporter'
Turn.config do |c|
c.natural = true
c.ansi = true
c.format = :pretty
end
Gemfile
source 'https://rubygems.org'
# core
gem 'rails', '3.2.8'
gem 'thin'
# infrastructure
gem 'heroku'
gem 'foreman', :groups => [:development, :test]
# application monitoring
gem 'airbrake'
gem 'newrelic_rpm'
# view engine
gem 'haml', '>= 3.1.7'
gem 'haml-rails', '>= 0.3.5'
gem 'redcarpet' # markdown
# data persistence
gem 'mongoid', '>= 3.0.5'
gem 'redis'
gem 'redis-store'
gem 'redis-rails'
# email
gem 'sendgrid'
gem 'mailcatcher', :group => [:development]
# authentication and authorization
gem 'devise', '>= 2.1.2'
gem 'omniauth', '>= 1.0'
#gem 'authority'
gem 'cancan'
gem 'rolify', '>= 3.2.0'
# view helpers
gem 'bootstrap-generators', '~> 2.1', :group => [:development]
gem 'jquery-rails'
gem 'simple_form', '>= 2.0.2'
gem 'rails3-jquery-autocomplete'
# file attachments
gem 'rmagick'
gem 'fog'
gem 'carrierwave'
gem 'carrierwave-mongoid', :require => 'carrierwave/mongoid'
# url helpers
gem 'mongoid_slug'
# console tools
gem 'ansi', :groups => [:development, :test]
gem 'rack-livereload', :groups => [:development]
gem 'pry-rails', :groups => [:development]
gem 'growl', :groups => [:development, :test]
gem 'turn', :groups => [:test]
gem 'awesome_print'
gem 'progress_bar', :groups => [:test]
# supporting libraries
gem 'bson_ext'
gem 'nokogiri', :group => :test
gem 'ruby_parser', '>= 2.3.1', :group => :test
gem 'rb-fsevent', '~> 0.9.1', :group => :development
# assets
gem 'less-rails', :group => :assets
gem 'therubyracer', '>= 0.10.2', :group => :assets
gem 'uglifier', '>= 1.0.3', :group => :assets
# guard
gem 'guard', :group => :development
gem 'guard-livereload', :group => :development
gem 'guard-spork', :group => :development
gem 'guard-minitest', :group => :development
gem 'guard-bundler', :group => :development
# minitest
gem 'spork-minitest', :group => :test
gem 'minitest-rails', :group => :test
gem 'minitest-rails-shoulda', :group => :test, :git => 'git://github.com/rawongithub/minitest-rails-shoulda.git'
gem 'capybara_minitest_spec', :group => :test
# mocking
gem 'mocha', :group => :test
# http testing
gem 'vcr', :group => :test
gem 'webmock', :group => :test
# factories
gem 'factory_girl_rails'
It appears that Spork and Minitest were actually not working as expected. In order to fix this, the following changes had to be made:
Inside of the Guardfile, :drb => true had to be added to minitest:
guard 'minitest', :drb => true do
#...
end
However that alone will break guard/minitest/spork because it tries to force feed it the -r -e options which are not currently supported. You'll run into the following error:
Running: test/models/business_test.rb
Running tests with args ["-r", "/Users/chance/.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/guard-minitest-0.5.0/lib/guard/minitest/runners/default_runner.rb", "-e", "::GUARD_NOTIFY=true", "test/test_helper.rb", "./test/models/business_test.rb"]...
Exception encountered: #<LoadError: cannot load such file -- -r>
backtrace:
/Users/chance/.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/activesupport-3.2.8/lib/active_support/dependencies.rb:251:in `require'
/Users/chance/.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/activesupport-3.2.8/lib/active_support/dependencies.rb:251:in `block in require'
/Users/chance/.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/activesupport-3.2.8/lib/active_support/dependencies.rb:236:in `load_dependency'
/Users/chance/.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/activesupport-3.2.8/lib/active_support/dependencies.rb:251:in `require'
/Users/chance/.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/spork-minitest-0.0.3/lib/spork/test_framework/minitest.rb:13:in `block in run_tests'
/Users/chance/.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/spork-minitest-0.0.3/lib/spork/test_framework/minitest.rb:12:in `each'
/Users/chance/.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/spork-minitest-0.0.3/lib/spork/test_framework/minitest.rb:12:in `run_tests'
/Users/chance/.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/spork-0.9.2/lib/spork/run_strategy/forking.rb:13:in `block in run'
/Users/chance/.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/spork-0.9.2/lib/spork/forker.rb:21:in `block in initialize'
/Users/chance/.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/spork-0.9.2/lib/spork/forker.rb:18:in `fork'
/Users/chance/.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/spork-0.9.2/lib/spork/forker.rb:18:in `initialize'
/Users/chance/.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/spork-0.9.2/lib/spork/run_strategy/forking.rb:9:in `new'
/Users/chance/.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/spork-0.9.2/lib/spork/run_strategy/forking.rb:9:in `run'
/Users/chance/.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/spork-0.9.2/lib/spork/server.rb:48:in `run'
/Users/chance/.rbenv/versions/1.9.3-p125/lib/ruby/1.9.1/drb/drb.rb:1548:in `perform_without_block'
/Users/chance/.rbenv/versions/1.9.3-p125/lib/ruby/1.9.1/drb/drb.rb:1508:in `perform'
/Users/chance/.rbenv/versions/1.9.3-p125/lib/ruby/1.9.1/drb/drb.rb:1586:in `block (2 levels) in main_loop'
/Users/chance/.rbenv/versions/1.9.3-p125/lib/ruby/1.9.1/drb/drb.rb:1582:in `loop'
/Users/chance/.rbenv/versions/1.9.3-p125/lib/ruby/1.9.1/drb/drb.rb:1582:in `block in main_loop'
Done.
Fortunately, there is a pull request for spork-minitest that fixes it.
Once the gem was pointed over to the repo, it took a nice cut out of the load times. It isn't anywhere near as fast as node.js and mocha, but it is at least faster than rspec.
I am trying to upload image at aws.
class Asset < ActiveRecord::Base
belongs_to :post
attr_accessible :image
has_attached_file :image, :styles => { :medium => "640x480>",
:thumb => "100x100#"},
:storage => :s3,
:s3_credentials => "#{Rails.root}/config/s3.yml",
:path => ":attachment/:id/:style.:extension",
:bucket => 'yourbucket'
end
s3.yml
development:
access_key_id: xxxxxxxx
secret_code: xxxxx
I am getting a message
AWS::Errors::MissingCredentialsError in PostsController#create
Missing Credentials.
Unable to find AWS credentials. You can configure your AWS credentials
a few different ways:
* Call AWS.config with :access_key_id and :secret_access_key
* Export AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY to ENV
* On EC2 you can run instances with an IAM instance profile and credentials
will be auto loaded from the instance metadata service on those
instances.
* Call AWS.config with :credential_provider. A credential provider should
either include AWS::Core::CredentialProviders::Provider or respond to
the same public methods.
= Ruby on Rails
In a Ruby on Rails application you may also specify your credentials in
the following ways:
Via a config initializer script using any of the methods mentioned above
(e.g. RAILS_ROOT/config/initializers/aws-sdk.rb).
Via a yaml configuration file located at RAILS_ROOT/config/aws.yml.
This file should be formated like the default RAILS_ROOT/config/database.yml
file.
I believe I am doing the last step.
Gemfile
gem 'rails', '3.1.3'
gem 'mysql'
gem 'koala'
gem 'paperclip'
gem 'aws-s3'
gem 'aws-sdk'
The following worked for me:
Create a file in your initializers called aws.rb
Put in the following in your aws.rb file:
AWS.config(
access_key_id: 'your_access_key',
secret_access_key: 'your_secret_access_key')
Then my paperclip options looks like this:
has_attached_file :photo, :styles => { :medium => "300x300>", :thumb => "100x100>" },
:default_url => "missing_:style.png", :default_url => 'missing_:style.png', :storage =>
:s3, :bucket => "<my_bucket>"
I am working with Paperclip and AWS and can successfully get the upload to work on my local host. The problem I run into is when I upload the app to Heroku I get:
AWS::S3::Errors::SignatureDoesNotMatch (The request signature we calculated does not match the signature you provided. Ch
eck your key and signing method.)
Locations.rb
has_attached_file :photo,
:styles => { :thumb => "150x150#", :medium => "200x200#", :small => "50x50"},
:path => ":attachment/:id/:style.:extension",
:s3_domain_url => "adsimgstore.s3.amazonaws.com",
:storage => :s3,
:s3_credentials => S3_CREDENTIALS,
:bucket => 'adsimgstore',
:s3_permissions => :public_read,
:convert_options => { :all => "-auto-orient" }
s3 initialize
# initializers/s3.rb
if Rails.env == "production"
# set credentials from ENV hash
S3_CREDENTIALS = { :access_key_id => ENV['S3_KEY'], :secret_access_key => ENV['S3_SECRET'], :bucket => "adsimgstore"}
else
# get credentials from YML file
S3_CREDENTIALS = Rails.root.join("config/s3.yml")
end
I have followed the Heroku tutorial https://devcenter.heroku.com/articles/s3 and added all keys
Any suggestions?
AWS::S3::Errors::SignatureDoesNotMatch (The request signature we calculated does not match the signature you provided. Ch
eck your key and signing method.):
2012-05-01T18:01:02+00:00 app[web.1]:
2012-05-01T18:01:02+00:00 app[web.1]: app/controllers/locations_controller.rb:76:in `block in update'
2012-05-01T18:01:02+00:00 app[web.1]: app/controllers/locations_controller.rb:75:in `update'
2012-05-01T18:01:02+00:00 app[web.1]:
check if your environment variables match
if you followed the heroku tutorial your environment variables would be AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY.
run heroku config to check your env variables.
no :bucket in Credentials
You put the :bucket option in the S3_CREDENTIALS-hash in the initializers/s3.rb file. the bucket-option doesn't belong here - you already set it in the has_attached_file method.
Hi I just migrated to heroku cedar stack. app is Rails 3, ive been using paperclip on s3 just fine previously. my gemfile has:
gem 'paperclip', '2.3.11'
gem 'aws-s3', '0.6.2'
my model file has:
class UserProfile < ActiveRecord::Base
has_attached_file :avatar,
:styles => { :thumb => "150x200#" },
:default_style => :thumb,
:default_url => "missingAvatar.png",
:storage => :s3,
:s3_credentials => S3_CREDENTIALS
Ive created a new file to store S3_CREDENTIALS,:
# initializers/s3.rb
if Rails.env == "production"
# set credentials from ENV hash
S3_CREDENTIALS = { :access_key_id => ENV['S3_KEY'], :secret_access_key => ENV['S3_SECRET'], :bucket => "app_content"}
else
# get credentials from YML file
S3_CREDENTIALS = Rails.root.join("config/s3.yml")
end
... with s3.yml containing my keys for local dev, and the keys set in heroku config:
S3_KEY => AK...
S3_SECRET => FFE...
as mentioned, everything works just fine on local. i can even see the existing avatars from before. just, when i try to upload anything new, i get no errors in heroku logs, but the picture never uploads.
ive went thru many stackoverflow issues, but none matching this. can anyone help??
Try adding the following to your model
class UserProfile < ActiveRecord::Base
has_attached_file :avatar,
:styles => { :thumb => "150x200#" },
:default_style => :thumb,
:default_url => "missingAvatar.png",
:storage => :s3,
:s3_credentials => S3_CREDENTIALS,
:url => "/assets/avatar/:id/:style/:basename.:extension",
:path => ":rails_root/public/assets/avatar/:id/:style/:basename.:extension"
The missing path / default path might be causing an issue.
turns out i needed to upgrade my paperclip gem to '2.4.5'
i did this in my Gemfile, then bundle update, and it worked!
I followed the installation procedure of geokit-rails3, here is my conf :
Using rails (3.0.4)
Using activerecord (3.0.4)
Using geokit (1.5.0)
Using geokit-rails (1.1.4)
I get this error "undefined method `within' for #" when i try to query with the "within" method. (note that i am new to rails and maybe missing something obvious)
Here is my class definition :
class Snip < ActiveRecord::Base
belongs_to :user
acts_as_mappable :default_units => :kms,
:default_formula => :sphere,
:distance_field_name => :distance,
:lat_column_name => :latitude,
:lng_column_name => :longitude
end
In my controller i have :
#userLocation = GeoKit::LatLng.new(params[:lat],params[:lng])
#snips = Snip.within(params[:distance], :origin => #userLocation)
Here is what i added to my gemfile :
gem 'geokit', '>= 1.5.0'
gem 'geokit-rails', '1.1.4'
Do you have any idea why i get this error ?
Thanks in advance,
Vincent.
Your gemfile asks for geokit-rails, that's the Rails 2 version. You need to replace that with geokit-rails3