please, could you please have a look to my config? I'm trying to setup carrierwave in my app but it doesn't work in the production server. It's working locally even as production environment. The thing is that it's saving the images into the tmp directory but the result is 'Empty file upload result'. I tried save to file and save to S3, same result. I'm using Passenger - Nginx.
I'm getting mad with this for two days now. Any idea or tip even about how I can debug this is welcome. I setup all permissions so I don't think it's a permissions issue. It could be a cache thing, the files are stored into tmp directory but it seems that the app don't see them as owned by the user???
Thanks!!!
#application.rb
require File.expand_path('../boot', __FILE__)
require 'rails/all'
if defined?(Bundler)
Bundler.require(*Rails.groups(:assets => %w(development test)))
end
module MyApp
class Application < Rails::Application
config.encoding = "utf-8"
config.filter_parameters += [:password]
config.active_support.escape_html_entities_in_json = true
config.active_record.whitelist_attributes = true
config.assets.initialize_on_precompile = false
config.assets.enabled = true
config.assets.version = '1.0'
end
end
# avatar_uploader.rb
class AvatarUploader < CarrierWave::Uploader::Base
include CarrierWave::MiniMagick
include ActiveModel::Conversion
extend ActiveModel::Naming
def extension_white_list
%w(jpg jpeg gif png mp3)
end
include Sprockets::Helpers::RailsHelper
include Sprockets::Helpers::IsolatedHelper
storage :fog
def store_dir
"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end
version :thumb do
process :resize_to_fill => [200,200]
end
end
# carrierwave.rb
CarrierWave.configure do |config|
config.fog_credentials = {
:provider => 'AWS', # required
:aws_access_key_id => 'ACCESS', # required
:aws_secret_access_key => 'SECRET', # required
:region => 'eu-west-1' # optional, defaults to 'us-east-1'
}
config.fog_directory = 'my_app_bucket'
end
# production.rb
MyApp::Application.configure do
config.cache_classes = true
config.consider_all_requests_local = true # default false, debug true
config.action_controller.perform_caching = true #default true
config.serve_static_assets = true # Carrierwave true - Default false
config.assets.compress = true
config.assets.compile = false # false for real production
config.assets.digest = true
config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for nginx
config.log_level = :debug
config.cache_store = :dalli_store
config.assets.precompile += %w( search.js )
config.i18n.fallbacks = true
config.active_support.deprecation = :notify
config.action_mailer.default_url_options = { :host => 'localhost' }
end
Solved!
My ImageMagick install was missing delegates. Now:
convert -list configure
DELEGATES bzlib fontconfig freetype jpeg jng lqr pango png x11 xml zlib
Related
I am using carrier wave for image uploads and for testing purposes I don't want to use s3 storage.
This is the carrierwave.rb file
CarrierWave.configure do |config|
config.permissions = 0666
config.directory_permissions = 0777
config.fog_directory = 'xxx-development'
config.storage = :file
config.enable_processing = false
end
And in the ImageUploader class I have
storage :file
def store_dir
"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end
version :thumb do
process resize_to_fill: [300, 300]
end
And when I push to heroku I get the following error:
rake aborted!
Fog provider can't be blank, Fog directory can't be blank
What is it I am doing wrong ?
If you want it conditional, perhaps set an environment condition on the fog_directory?
CarrierWave.configure do |config|
config.permissions = 0666
config.directory_permissions = 0777
config.fog_directory = 'xxx-development' unless Rails.env.development?
config.storage = :file
config.enable_processing = false
end
Hello i have this in routes.rb
namespace :admin do
root :to => "admin#index"
resources :employees
resources :customers
resources :users
end
frontend normally works, i can login to administration but there i have link like
<li><%= link_to "users", admin_users_path %></li>
etc..
if i click on that link i get this error
uninitialized constant Admin::UsersController
or if i click on admin_employees_path i get
uninitialized constant Admin::EmployeesController
and that behavior is at every link in administration
at server with rails s everything is fine :p
user controller is defined like that
class UsersController < Admin::AdminController
files location
controllers/admin/admin_controller.rb
controllers/users_controller.rb
My environments files
development.rb
Web::Application.configure do
config.cache_classes = false
config.whiny_nils = true
config.consider_all_requests_local = true
config.action_controller.perform_caching = false
config.action_mailer.raise_delivery_errors = false
config.active_support.deprecation = :log
config.action_dispatch.best_standards_support = :builtin
config.active_record.mass_assignment_sanitizer = :strict
config.active_record.auto_explain_threshold_in_seconds = 0.5
config.assets.compress = false
config.assets.debug = true
end
production.rb
Web::Application.configure do
config.cache_classes = true # different
config.assets.compress = true # different
config.consider_all_requests_local = true # temporary true
config.action_controller.perform_caching = false
# not in development
config.serve_static_assets = false
config.assets.compile = true
config.assets.digest = true
config.i18n.fallbacks = true
config.active_support.deprecation = :notify
end
You are defining your users resource under the admin namespace but not defining it in the controller.
Move your users_controller to /controllers/admin/users_controller and append the namespace to that class declaration
class Admin::UsersController < Admin::AdminController
Or move your
resources :user outside the admin namespace.
I can't for the life of me seem to set up rspec/capybara in a way that doesn't throw random errors from time to time. My most common errors (but not consistent) are along the lines of:
An error occurred in an after hook
ActiveRecord::RecordNotFound: Couldn't find Post with id=1
occurred at [...]/gems/activerecord-3.2.11/lib/active_record/relation/finder_methods.rb:341:in `find_one'
And a close second is anything related to expecting model objects that were created within the spec and then not found later. e.g. something like
Sorter should populate featured_posts with appropriate posts
Failure/Error: Sorter.top_4.map(&:id).should eq(([best_new_post, best_old_post] + new_posts.last(2).reverse).map(&:id))
expected: [2, 1, 40, 38]
got: []
These tests will always pass when I run them individually, and they don't always fail when I run them in the suite. I'm assuming there is some sort of issue with threads and how the database is set up, but I can't seem to figure it out.
My spec_helper.rb is a hodgepodge of advice from various sources:
require 'rubygems'
require 'spork'
Spork.prefork do
ENV["RAILS_ENV"] ||= 'test'
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
require 'rspec/autorun'
require 'capybara/rspec'
require 'capybara/email/rspec'
include ApplicationHelper
Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
include Warden::Test::Helpers
Warden.test_mode!
ActionController::Base.asset_host = "http://localhost:3000"
RSpec.configure do |config|
config.include Rails.application.routes.url_helpers
config.use_transactional_fixtures = false
config.use_transactional_examples = false #factoryGirl
# From http://railsapps.github.io/tutorial-rails-devise-rspec-cucumber.html
config.before(:suite) do
DatabaseCleaner.strategy = :truncation
DatabaseCleaner.clean_with(:truncation)
end
config.before(:each) { DatabaseCleaner.start }
config.after(:each) { DatabaseCleaner.clean }
#
config.infer_base_class_for_anonymous_controllers = false
## Setting up email helpers
config.include MailerMacros
config.before(:each) { reset_email }
## Setting up test and login helpers for Devise testing
config.include Devise::TestHelpers, type: :controller
config.extend ControllerMacros, type: :controller
# From http://railscasts.com/episodes/413-fast-tests
config.order = "random"
config.include FactoryGirl::Syntax::Methods
config.treat_symbols_as_metadata_keys_with_true_values = true
config.filter_run focus: true
config.run_all_when_everything_filtered = true
config.filter_run_excluding :slow unless ENV["SLOW_SPECS"]
config.before(:all) { DeferredGarbageCollection.start }
config.after(:all) { DeferredGarbageCollection.reconsider }
end
end
Spork.each_run do
Rails.cache.clear
Warden.test_reset!
FactoryGirl.reload
end
I've tried removing pieces to troubleshoot, but it's hard to gauge whether it hss solved anything since the errors are sporadic.
Is there anything here that stands out as an obvious reason for the errors above, or any advice on how to troubleshoot this?
In your spec_helper.rb, try setting
config.use_transactional_fixtures = true
I'm working on a ruby on rails project made mostly by someone else, and my rails knowledge is so-so.
The registration process works like this (or used to, but doesn't seem to now, for some reason):
A person registers with name, email, password. (All done with Devise)
The person is sent an email, asking them to click on a link, and when they do, they are then a registered user and can log in to the app with their name and password.
When they do step 1 and click 'Sign Up' a message comes up on the screen, 'Congratulations! Check your email and click the link.'
But no email is being sent. In my App/config/environments/development.rb I have:
QuestionnaireSite::Application.configure do
# Settings specified here will take precedence over those in config/application.rb
# In the development environment your application's code is reloaded on
# every request. This slows down response time but is perfect for development
# since you don't have to restart the web server when you make code changes.
config.cache_classes = false
# Log error messages when you accidentally call methods on nil.
config.whiny_nils = true
# Show full error reports and disable caching
config.consider_all_requests_local = true
config.action_controller.perform_caching = false
# Don't care if the mailer can't send
config.action_mailer.raise_delivery_errors = false
config.action_mailer.default_url_options = { :host => 'localhost:3000' }
config.action_mailer.delivery_method = :smtp
# config.action_mailer.delivery_method = :letter_opener
config.action_mailer.smtp_settings = {
:address => 'smtp.gmail.com',
:port => 587,
:domain => 'gmail.com',
:user_name => 'questionnaire.dev#gmail.com',
:password => 'qwerty_123',
:authentication => 'plain',
:enable_starttls_auto => true
}
# Print deprecation notices to the Rails logger
config.active_support.deprecation = :log
# Only use best-standards-support built into browsers
config.action_dispatch.best_standards_support = :builtin
# Raise exception on mass assignment protection for Active Record models
config.active_record.mass_assignment_sanitizer = :strict
# Log the query plan for queries taking more than this (works
# with SQLite, MySQL, and PostgreSQL)
config.active_record.auto_explain_threshold_in_seconds = 0.5
# Do not compress assets
config.assets.compress = false
# Expands the lines which load the assets
config.assets.debug = true
config.cache_store = :mem_cache_store
end
When I comment out the line:
config.action_mailer.delivery_method = :smtp
and uncomment:
# config.action_mailer.delivery_method = :letter_opener
Everything works as planned (letter_opener is a gem that automates the registration process) so I know there's something going on in this file. As I said, it was working before, and I'm pretty sure those are the only lines I've changed. Is there something else I should be doing?
You need the following in your development.rb file as well as all the other stuff:
config.action_mailer.perform_deliveries = true
Without the above, your app won't actually send the email, and instead will simply display it's contents in your server log... Check the command line output (where rails server is running)
Note: this setting is enabled by default in production, so there's no need to specify it there
First of all, thank you all above for your help and guidance.
#Peter Klipfel - in fact, you were right. I was simply refreshing my app, therefore no error messages with:
config.action_mailer.raise_delivery_errors = false
I had to restart webrick for it to take effect. When that was done I got the error:
Net::SMTPAuthenticationError in Devise::RegistrationsController#create
username and password don't match
As I said, I inherited this project from someone else - questionnaire.dev#gmail probably doesn't exist any more. I changed that part of the code to:
config.action_mailer.raise_delivery_errors = true
config.action_mailer.default_url_options = { :host => 'localhost:3000' }
config.action_mailer.perform_deliveries = true
config.action_mailer.default :charset => "utf-8"
config.action_mailer.delivery_method = :smtp
# config.action_mailer.delivery_method = :letter_opener
config.action_mailer.smtp_settings = {
:address => 'smtp.gmail.com',
:port => 587,
# in previous Stackoverflow I read :domain part wasn't needed, so leave it out
# :domain => 'gmail.com',
:user_name => 'my_gmail_address#gmail.com',
:password => 'my_gmail_password',
:authentication => 'plain',
:enable_starttls_auto => true
}
And now everything works as it should (for the moment anyway!)
I am trying to crop image using mini magick gem with carrierwave. I am facing following issue when i am creating user.
Errno::ENOENT in UsersController#create
No such file or directory - identify -ping /tmp/mini_magick20120919-5600-ai31ph.jpg
My Code :
model/user.rb
class User < ActiveRecord::Base
attr_accessor :crop_x, :crop_y, :crop_h, :crop_w
attr_accessible :username,:profile
after_update :reprocess_profile, :if => :cropping?
#field :username
mount_uploader :profile, ProfileUploader
def cropping?
!crop_x.blank? and !crop_y.blank? and !crop_h.blank? and !crop_w.blank?
end
def profile_geometry
#img = MiniMagick::Image.open(self.profile.large.path)
##geometry = {:width => img[:width], :height => img[:height] }
end
private
def reprocess_profile
#puts self.profile.large.path
#img = MiniMagick::Image.open(self.profile.large.path)
#crop_params = "#{crop_w}x#{crop_h}+#{crop_x}+#{crop_y}"
#img.crop(crop_params)
#img.write(self.profile.path)
#profile.recreate_versions!
end
end
uploader/profile_uploader.rb
# encoding: utf-8
class ProfileUploader < CarrierWave::Uploader::Base
# Include RMagick or ImageScience support:
#include CarrierWave::RMagick
# include CarrierWave::ImageScience
include CarrierWave::MiniMagick
# Choose what kind of storage to use for this uploader:
storage :file
# storage :fog
# Override the directory where uploaded files will be stored.
# This is a sensible default for uploaders that are meant to be mounted:
def store_dir
"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end
def extension_white_list
%w(jpg jpeg gif png)
end
version :large do
end
version :thumb do
process :resize_to_fill => [100, 100]
end
end
What would be the problem ? please suggest any solution.
Need to install imagemagick.
In ubuntu:
sudo apt-get install imagemagick