ActiveAttr stops working on production server - ruby-on-rails

I have created a simple model for handling a contact form:
class ContactForm
include ActiveAttr::Model
attribute :name
attribute :email
attribute :message
attr_accessible :name, :email, :message
validates_presence_of :name, :email, :message
validates_format_of :email, :with => /^[-a-z0-9_+\.]+\#([-a-z0-9]+\.)+[a-z0-9] {2,4}$/i
end
It works fine on the development environment, but gives me an error on the production server, logged in the unicorn log:
E, [2013-01-26T18:15:42.724973 #8940] ERROR -- : uninitialized constant ContactForm::ActiveAttr (NameError)
Gemfile
source 'https://rubygems.org'
gem 'rails', '3.2.11'
# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'
gem 'pg'
gem 'bootstrap-sass'
gem 'font-awesome-sass-rails'
# gem 'acts_as_tree', :git => 'git://github.com/amerine/acts_as_tree.git'
gem 'closure_tree'
gem 'kaminari'
gem 'friendly_id'
gem 'slim'
gem 'gmaps4rails'
gem 'devise'
gem 'omniauth'
gem 'oauth2'
gem 'omniauth-facebook'
gem 'omniauth-twitter'
gem 'simple_form'
gem 'pg_search'
gem 'stamp'
gem 'acts-as-taggable-on', '~> 2.3.1'
gem 'rmagick'
gem 'carrierwave'
gem 'active_attr'
gem 'select2-rails'
# gem 'roo'
# Gems used only for assets and not required
# in production environments by default.
group :assets do
gem 'sass-rails', '~> 3.2.3'
gem 'coffee-rails', '~> 3.2.1'
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
# gem 'therubyracer', :platforms => :ruby
gem 'uglifier', '>= 1.0.3'
gem 'compass-rails'
end
group :development do
gem "better_errors"
gem "binding_of_caller"
gem 'guard'
gem 'letter_opener'
end
group :test do
gem 'minitest'
end
gem 'jquery-rails'
# To use ActiveModel has_secure_password
# gem 'bcrypt-ruby', '~> 3.0.0'
# To use Jbuilder templates for JSON
# gem 'jbuilder'
# Use unicorn as the app server
gem 'unicorn'
# Deploy with Capistrano
gem 'capistrano'
# To use debugger
# gem 'debugger'
gem 'bullet', :group => :development
gem 'rack-mini-profiler'

I had the same problem and the fix for me was to specify the version of active_attr in my gemfile.
gem 'active_attr', '0.7.0'
I found an issue on GitHub where someone else had the same problem here.

I have the same problem in development environment.
I followed this step-by-step tutorial https://github.com/thomasklemm/email_form_rails.
When I try to create a new message in console I get :
m=Message.new
NameError: uninitialized constant Message::ActiveAttr
I use Rails 3.2.1, active_attributes gem version is 0.0.1.
EDIT
My fault it seems I made a mistake when installing the gem (not the good one)
change gemfile from
gem 'active_attributes','0.0.1'
to
gem 'active_attr', '0.0.7'
Now it seems to work...

Related

No connection pool with 'primary' found

I am using rails 5.2.3 and ruby 2.5.2 version , In my work i have two active job classes that will perform two jobs parallel , I am using MSSQL database and having "No connection pool with 'primary' found" issue when it started working in parallel .
Can anyone help me to resolve this .
#source 'https://rubygems.org'
source 'http://production.cf.rubygems.org'
#source 'http://rubygems.org'
gem 'rails', '5.2.3'
gem 'log4r'
gem 'will_paginate'
gem 'bcrypt'
# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'
gem 'activesupport'
gem 'activerecord-sqlserver-adapter'
gem 'tiny_tds'
gem 'sequel'
gem 'mysql2', '~> 0.5.2 '
gem 'bootsnap'
gem 'capybara'
gem 'poltergeist', :group => [:development, :test]
gem "rspec-rails", :group => [:development, :test]
gem 'public_suffix'
gem 'xpath'
gem 'nokogiri'
gem 'byebug', '~> 11.1', '>= 11.1.1'
gem 'activewarehouse-etl', '~> 1.0'
gem 'table_print'
gem 'sidekiq'
#gem 'pg'
gem 'adapter_extensions', '~> 0.9.5.rc1'
gem 'test-unit'
gem "iconv", "~> 1.0.3"
gem 'fileutils'
gem 'json'
# Gems used only for assets and not required
# in production environments by default.
gem 'stupidedi'
gem 'sass-rails'
gem 'sass'
gem 'coffee-rails'
gem 'mailfactory'
gem 'rake'
gem 'rack-cache'
gem 'listen'
gem 'thor'
gem 'openssl'
gem 'rb-inotify'
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
gem 'therubyrhino'
gem 'uglifier'
group :assets do
end
gem 'rubyzip', '>= 1.0.0'
gem 'axlsx'
gem "axlsx_rails"
gem 'prawn'
gem 'typhoeus'
gem 'tlsmail'
gem 'net_http_ssl_fix'
gem 'simple_xlsx_reader'
gem 'spreadsheet'
# To use ActiveModel has_secure_password
# gem 'bcrypt-ruby', '~> 3.0.0'
# To use Jbuilder templates for JSON
# gem 'jbuilder'
# Use unicorn as the app server
# gem 'unicorn'
# Deploy with Capistrano
# gem 'capistrano'
# To use debugger
# gem 'debugger'

Why are Rails validations not working?

I'm following the Rails guide to create a very vanilla validation. I've created a callback that works fine, but the validates:
class Group < ActiveRecord::Base
include ActiveModel::ForbiddenAttributesProtection
  validates :name, :presence => true
end
results in:
undefined method ` validates' for #<Class:0x007fa57b1a9e60>
This is Rails 3.2.13 with the following gemfile
source 'https://rubygems.org'
gem 'rails', '3.2.13'
gem 'pg'
group :assets do
gem 'sass-rails'
gem 'uglifier'
end
gem 'jquery-rails'
gem 'strong_parameters'
gem 'bootstrap-sass', '>= 2.3.0.0'
gem 'devise', '>= 2.2.3'
gem 'cancan', '>= 1.6.9'
gem 'omniauth'
gem 'omniauth-facebook'
gem 'paperclip', '~> 3.0'
gem 'friendly_id', "~> 4.0.9"
group :test, :development do
gem 'rspec-rails'
gem 'factory_girl_rails'
end
Use validates_presence_of :name.

compass install bootstrap -> NoMethodError on line ["32"] ... sass-rails-3.2.6/lib/sass/rails/helpers.rb: undefined method `[]' for nil:NilClass

After running this command
compass install bootstrap
I get this message:
identical sass/styles.scss
...
identical javascripts/bootstrap-typeahead.js
NoMethodError on line ["32"] of /Users/xxx/.rvm/gems/ruby-1.9.3-p327#favy/gems/sass-rails-3.2.6/lib/sass/rails/helpers.rb: undefined method `[]' for nil:NilClass
Run with --trace to see the full backtrace
in /Users/xxx/.rvm/gems/ruby-1.9.3-p327#favy/gems/sass-rails-3.2.6/lib/sass/rails/helpers.rb
31 def resolver
32 options[:custom][:resolver]
33 end
I tried a workaround -> https://gist.github.com/castus/4044953
def resolver
if ::Rails::env == "production"
options[:custom][:resolver]
else
Resolver.new(CompassRails.context)
end
end
& still no luck :)
I have this stuff in my config/compass.rb
require 'bootstrap-sass'
And my Gemfile
source 'http://rubygems.org'
gem "paperclip"
gem 'bootstrap-sass', '~> 2.3.1.0'
gem 'compass-rails'
gem 'bootswatch-rails'
gem 'gmaps4rails'
gem 'rails', '3.2.13'
gem 'activerecord-postgresql-adapter'
gem 'devise'
gem 'sass-rails', '~> 3.2.3'
gem "haml"
gem "haml-rails"
# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'
# Gems used only for assets and not required
# in production environments by default.
group :assets do
gem 'sass-rails', '~> 3.2.3'
gem 'coffee-rails', '~> 3.2.1'
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
# gem 'therubyracer', :platforms => :ruby
gem 'uglifier', '>= 1.0.3'
end
gem 'jquery-rails'
# To use ActiveModel has_secure_password
# gem 'bcrypt-ruby', '~> 3.0.0'
# To use Jbuilder templates for JSON
# gem 'jbuilder'
# Use unicorn as the app server
# gem 'unicorn'
# Deploy with Capistrano
# gem 'capistrano'
# To use debugger
# gem 'debugger'
You don't need "Compass" at all if you are using Rails and Bootstrap-sass. Compass is for sites not using Rails.
Here are steps to install and bootstrap-sass
Add it to Gemfile and bundle install
Rename application.css to application.css.scss
Remove all comments in application.css.scss, make it blank
Add #import bootstrap
You are done! Treat it as normal css file and use #import to do whatever you like. But no more require in comment!

Why am I getting this simple error when using `acts_as_taggable_on`?

I wanted to set up ActsAsTaggableOn.strict_case_match = true
According to http://5minutenpause.com/blog/2012/11/20/careful-where-you-get-your-gems-from/, it seems I have to download the gem from github. So I made it that way and tried to run App.
However, it returns this error:(
Error message: (I've tried bundle install but still the same error message!)
git://github.com/mbleigh/acts-as-taggable-on.git (at master) is not checked out. Please run `bundle install` (Bundler::GitError)
Exception class:
PhusionPassenger::UnknownError
Here are my codes!
config/initializer/tag_list.rb
ActsAsTaggableOn.delimiter = ','
ActsAsTaggableOn.remove_unused_tags = true
ActsAsTaggableOn.strict_case_match = true
Gemfile
gem 'acts-as-taggable-on', git: 'git://github.com/mbleigh/acts-as-taggable-on.git'
I made a try to change the source to download the gem directly from to rubyorg, not from the Github. It's just like this.
gem 'acts-as-taggable-on', '2.3.3'
Now it returns this error:(
Error message:
undefined method `strict_case_match=' for ActsAsTaggableOn:Module
How can I solve this?
UPDATE:
Gemfile
source 'https://rubygems.org'
gem 'rails', '3.2.11'
# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'
gem 'mysql2'
gem 'execjs'
gem 'therubyracer'
gem 'devise', '2.0.1'
gem 'recaptcha', :require => 'recaptcha/rails'
gem 'paperclip', "~> 3.0"
gem "cocaine"
gem 'mailboxer', '0.7.0'
gem 'sunspot_rails'
gem 'sunspot_solr'
group :development do
gem 'better_errors'
gem 'binding_of_caller'
#gem 'rack-mini-profiler'
end
gem 'progress_bar'
gem 'kaminari', '0.14.0'
gem "sunspot_with_kaminari", '~> 0.1'
gem 'i18n_generators'
gem 'ancestry'
gem 'acts-as-taggable-on', '2.3.3'
gem 'acts_as_commentable_with_threading'
gem 'twitter-bootstrap-rails'
gem "less-rails"
gem 'crummy', '~> 1.6.0'
gem 'rails3_acts_as_paranoid'
gem 'galetahub-simple_captcha', :require => 'simple_captcha'
gem "acts_as_follower"
gem "jpmobile"
gem "rqrcode-rails3"
gem 'acts_as_votable', '~> 0.4.0'
gem 'rails3-jquery-autocomplete'
gem "cancan"
gem 'rinku', '1.5.1'
gem 'dalli'
gem "auto_html", '1.6.0'
gem "rails_autolink"
# Gems used only for assets and not required
# in production environments by default.
group :assets do
gem 'sass-rails', '~> 3.2.3'
gem 'coffee-rails', '~> 3.2.1'
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
# gem 'therubyracer', :platforms => :ruby
gem 'uglifier', '>= 1.0.3'
gem 'jquery-ui-rails'
end
gem 'jquery-rails'
# To use ActiveModel has_secure_password
# gem 'bcrypt-ruby', '~> 3.0.0'
# To use Jbuilder templates for JSON
# gem 'jbuilder'
# Use unicorn as the app server
# gem 'unicorn'
# Deploy with Capistrano
# gem 'capistrano'
# To use debugger
# gem 'debugger'
The problem is that the version 2.3.3 from acts-as-taggable-on was released 9 months ago and doesn't include the strict_case_match feature.
Your Gemfile has too look this this:
gem 'acts-as-taggable-on', git: 'git://github.com/mbleigh/acts-as-taggable-on.git'
the same way you had, and run:
bundle update acts-as-taggable-on
if that doesn't work, just delete your Gemfile.lock and run bundle install and bundle update
notice that its a development version of the gem, not ready for production, but you can take the risk and be a an alpha user of the gem and report any issue you find :)

Mercury: SyntaxError: cannot return a value from a constructor

Working on a fresh install of rails 3.2.8 and getting an error when compiling after adding Mercury:
SyntaxError: cannot return a value from a constructor: "this.element" in class Button
(in /home/*********/**************/vendor/bundle/ruby/1.8/bundler/gems/mercury-0c048033cd79/app/assets/javascripts/mercury/toolbar.button.js.coffee)
I've successfully installed Mercury using Rails 3.2.3, but haven't been able to figure why this wouldn't be working.
Any ideas?
source 'https://rubygems.org'
gem 'rails', '3.2.8'
# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'
gem 'mysql2'
gem 'bootstrap-sass'
gem 'simple_form'
gem 'json'
gem 'ckeditor'
gem 'mercury-rails', :git => 'https://github.com/jejacks0n/mercury.git'
gem 'jquery-rails'
# gem 'jquery-ui-rails'
gem "paperclip", "~> 2.7"
# To use ActiveModel has_secure_password
gem 'bcrypt-ruby', '~> 3.0.0'
# Gems used only for assets and not required
# in production environments by default.
group :assets do
gem 'sass-rails', '~> 3.2.3'
gem 'coffee-rails', '~> 3.2.1'
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
gem 'therubyracer', '0.10.2', :platforms => :ruby
gem 'libv8', '~> 3.3.10'
gem 'execjs'
gem 'uglifier', '>= 1.0.3'
end
https://github.com/jejacks0n/mercury/issues/349
i guess you need to lock into coffeescript 1.4.0
this fixed my issue.
Apparently, there is a fix, which is in the github repo, but not on rubygems, yet. If you don't want to downgrade coffee-script, just specify the repository in the Gemfile:
# Gemfile
# ...
gem 'mercury-rails', git: 'git://github.com/jejacks0n/mercury'
and run bundle update mercury-rails, afterwards. This fixed this problem for me without the need to downgrade coffee-script.
Here's what you actually need to type into your gemfile:
gem 'coffee-script-source', '1.4.0'

Resources