Why are Rails validations not working? - ruby-on-rails

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.

Related

active job with rails rspec

I have installed a gem rspec-rails. Everything is working fine except ActiveJob.
I have tried to implement the ActiveJob in RSpec with:
include ActiveJob::TestHelper
and here's the code for the RSsec Job Controller:
describe "#perform_later" do
it "Send Invoice Reminder" do
ActiveJob::Base.queue_adapter = :test
InvoiceReminderJob.perform_later
expect(InvoiceReminderJob).to have_enqueued_job
end
end
spec_helper.rb:
require 'rails_helper'
RSpec.describe InvoiceReminderJob, type: :job do
include ActiveJob::TestHelper
# pending "add some examples to (or delete) #{__FILE__}"
describe "#perform_later" do
it "Send Invoice Reminder" do
ActiveJob::Base.queue_adapter = :test
InvoiceReminderJob.perform("test")
expect(InvoiceReminderJob).to have_enqueued_job
end
end
end
invoice_reminder_job_spec.rb:
require 'rails_helper'
RSpec.describe InvoiceReminderJob, type: :job do
# include ActiveJob::TestHelper
# pending "add some examples to (or delete) #{__FILE__}"
describe "#perform_later" do
it "Send Invoice Reminder" do
ActiveJob::Base.queue_adapter = :test
InvoiceReminderJob.perform_later
expect(InvoiceReminderJob).to have_enqueued_job
end
end
end
When I am trying to run rspec with the command rspec I am getting the following error:
uninitialized constant ActiveJob (NameError)
Here is my Gemfile:
Here is the gemfile included for my project:
source 'https://rubygems.org'
ruby '2.1.2'
gem 'acts-as-taggable-on', '~> 3.4'
gem 'acts_as_tenant'
gem 'audited', '~> 4.0'
gem 'audited-activerecord'
gem 'aws-sdk', '~> 1.6'
gem 'axlsx'
gem 'best_in_place', '~> 3.0.1'
gem 'bootstrap-generators'
gem 'bootstrap-sass'
gem 'bullet', group: 'development'
gem 'cancancan', '~> 1.10'
gem 'clockwork'
gem 'coffee-rails', '~> 4.1.0'
gem 'daemons'
gem 'delayed_job_active_record'
gem 'devise'
gem 'eefgilm'
gem 'exception_notification'
gem 'figaro'
gem 'font-awesome-rails'
gem 'i18n-js', '>= 3.0.0.rc11'
gem 'jbuilder', '~> 2.0'
gem 'jquery-rails'
gem 'jquery-ui-rails'
gem 'mailman'
gem 'net-ssh'
gem 'paperclip', '~> 4.2'
gem 'pg'
gem 'protected_attributes'
gem 'puma'
gem 'rails', '4.1.5'
gem 'rails-console-tweaks'
gem 'rails-i18n'
gem 'rails_best_practices'
gem 'redcarpet'
gem 'rest-client'
gem 'roo'
gem 'roo-google'
gem 'roo-xls'
gem 'rubocop', require: false
gem 'sass-rails', '~> 5.0'
gem 'sdoc', '~> 0.4.0', group: :doc
gem 'seed_dump'
gem 'simple_form'
gem 'therubyracer', platforms: :ruby
gem 'traceroute'
gem 'twitter-bootstrap-rails'
gem 'uglifier', '>= 1.3.0'
gem 'whenever', :require => false
gem 'wicked_pdf'
gem 'wkhtmltopdf-binary'
gem 'zip'
group :development do
gem 'capistrano'
gem 'capistrano3-puma'
gem 'capistrano-bundler', require: false
gem 'capistrano-rails', require: false
gem 'capistrano-rvm'
gem 'rails-erd'
gem 'capistrano-rails-console', require: false
gem 'capistrano-maintenance', '~> 1.0', require: false
gem 'letter_opener'
gem 'rspec-rails'
gem 'faker'
end
group :production do
gem 'rails_12factor'
end
group :test do
gem 'shoulda-matchers'
gem 'database_cleaner'
gem 'simplecov'
end
group :development, :test do
gem 'byebug'
gem 'hirb'
gem 'mocha'
gem 'activejob'
gem 'factory_bot_rails'
end
And here is the output of bundle show activejob:
/Users/221/.rvm/gems/ruby-2.1.2/gems/activejob-0
I have tried to search with lots of solution but I am not able to resolve this issue. If anyone could help me with it, I would be really grateful.
You are using rails 4.1.5, ActiveJob is introduced in rails 4.2
This issue is resolved by using the gem "gem 'activejob_backport'

undefined method `[]' for "font":Sass::Script::Value::String

I am running my rails application I encountered the above error.
I guess it has something to do with sass rails and font awesome.
Here is my gemfile
source 'https://rubygems.org'
ruby '2.2.3'
gem 'rails', '4.2.6'
gem 'jquery-rails'
gem 'jquery-turbolinks'
gem 'jquery-ui-rails'
gem 'devise'
gem 'simple_form'
gem 'will_paginate'
gem 'bootstrap-will_paginate'
#gem 'activerecord-reputation-system', require: 'reputation_system'
gem 'activerecord-reputation-system', github: 'NARKOZ/activerecord-reputation-system', branch: 'rails4'
gem 'acts-as-taggable-on'
gem 'randumb'
gem 'turbolinks'
gem 'mobu'
#gem 'font_assets' rails 3?
#gem 'font-awesome-rails', '4.2' #'3.1.1.0'
gem 'font-awesome-rails'
gem 'protected_attributes' #for attr_accesible instead of strong params..
#this is active admin gem
#gem 'activeadmin', github: 'activeadmin'
gem 'activeadmin', '~> 1.0.0.pre2'
gem 'rack-cors', :require => 'rack/cors'
#group :assets do
gem 'sass-rails', '~> 5.0'
gem 'coffee-rails' #, '~> 3.2.1'
gem 'uglifier' #, '>= 1.0.3'
gem 'bootstrap-sass'
gem 'tzinfo-data' #rails 4 stuff
gem 'pg'
# this gem is used for pagination
#gem 'kaminari'
group :production do
#gem 'heroku-deflater' need rails 4 fix, this gem helps to optimize app performance
gem 'unicorn'
gem 'rails_12factor'
end
group :development, :test do
gem 'better_errors' #need ruby 2.0
end
I tried to update sass rails and sprockets but of no use.I have tried to use #import fontawesome in a stylesheet other than application.css.
In my case the trouble was a result of custom fonts.
Solution was to remove the 'font' parameter from the asset-url helper.
previous:
asset-url('custom-webfont.svg', 'font') format('svg');
new
asset-url('custom-webfont.svg') format('svg');

Deploy rails 3.2 app fails with capistrano filename too long

Needs help to solve fails capistrano deploy proccess.
We attempt to deploy our app with capistrano and it fails with cash error
GemFile look like this
source 'https://rubygems.org'
gem 'rails', '3.2.13'
gem 'mysql2'
gem 'haml'
gem 'rake', '10.0.3'
gem 'dalli'
gem 'russian'
gem 'kaminari'
gem "rails-settings-cached"
gem 'devise'
gem 'activeadmin'
gem 'enumerize'
gem 'rack-cache', :require => 'rack/cache'
gem 'dragonfly', '~> 0.9.12'
gem 'imperavi-rails', :github => 'Paxa/imperavi-rails', :ref => 'ec989856'
gem 'awesome_nested_set'
gem 'exception_notification', '2.6.1'
group :assets do
gem 'sass-rails', '~> 3.2.3'
gem 'coffee-rails', '~> 3.2.1'
gem 'uglifier', '>= 1.0.3'
gem 'therubyracer', '0.10.2', :platforms => :ruby
end
gem 'right-rails'
group :development do
gem 'hipchat'
gem 'capistrano'
gem 'capistrano_colors'
gem 'rvm-capistrano'
end
group :production do
gem 'thin'
end
In last commit was add right-dialog js and css
How can we fix this?
Thanks.

rails doorkeeper respond with 500 for some application setting

I am using doorkeeper for OAuth functionality on my ruby on rails application. Suddenly doorkeeper became unable to create token in production mode for some Doorkeeper::Application (i have three Doorkeeper::Application settings) without writing in the production log file, but yesterday it worked normally.
Every time on POST "/oauth/token" doorkeeper returns 500 page for this Doorkeeper::Application, but 201 for another one.
When I recreated Doorkeeper::Application configuration in database without changing parameters, doorkeeper began to work normally with this new record.
I am using postgres with doorkeeper v 0.6.7.
Here is my gemfile:
source 'https://rubygems.org'
def darwin_only(require_as)
RUBY_PLATFORM.include?('darwin') && require_as
end
def linux_only(require_as)
RUBY_PLATFORM.include?('linux') && require_as
end
gem 'rails', '3.2.16'
gem 'jquery-rails'
gem 'pg'
gem 'slim-rails'
gem 'inherited_resources'
gem 'simple_form'
gem 'twitter-bootstrap-rails'
gem 'airbrake', '3.1.2'
gem 'devise'
gem 'httparty'
gem 'ledermann-rails-settings', :require => 'rails-settings'
gem 'carrierwave', git: 'git://github.com/jnicklas/carrierwave.git', ref: '809e86b697'
gem 'mini_magick'
gem 'ruby-progressbar'
gem 'doorkeeper', '~> 0.6.7'
gem 'jsonify-rails'
gem 'less-rails'
gem 'therubyracer', '0.12.1'
gem 'cancan'
gem 'push-core', git: 'git://github.com/tompesman/push-core.git', ref: '980ddc107f'
gem 'push-apns'
gem 'push-gcm'
gem 'delayed_job_active_record'
gem 'daemons'
gem 'recaptcha', require: 'recaptcha/rails'
gem 'validates_timeliness'
gem 'paper_trail'
gem 'oj'
gem 'kaminari'
gem 'newrelic_rpm'
gem 'russian'
gem 'nested_form', '~> 0.3.2'
gem 'select2-rails'
gem 'jquery-ui-rails'
gem 'bourbon'
gem 'axlsx_rails'
gem 'sanitize'
gem 'gilenson'
gem 'ace-rails-ap'
gem 'activerecord-postgres-hstore'
gem 'geocoder'
gem 'rest-client'
gem 'figaro'
gem 'rails-erd'
gem 'acts_as_singleton'
gem 'carrierwave-processing'
group :development do
gem 'thin'
gem 'capistrano'
gem 'capistrano-ext'
gem 'rvm-capistrano'
gem 'yard'
gem 'quiet_assets'
gem 'pry-rails'
gem 'pry-plus'
gem 'ZenTest', '4.9.5'
end
# 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'
gem 'uglifier', '>= 1.0.3'
gem 'jquery-datatables-rails', git: 'git://github.com/rweng/jquery-datatables-rails.git'
end
group :test, :development do
gem 'rspec-rails', '~> 2.0'
gem 'spork-rails'
# Guard
gem 'guard-rspec'
gem 'guard-spork'
# File changes
gem 'rb-fsevent', require: darwin_only('rb-fsevent')
gem 'rb-inotify', require: linux_only('rb-inotify')
# Notifications
gem 'terminal-notifier-guard', require: darwin_only('terminal-notifier-guard')
end
group :test do
gem 'factory_girl_rails'
gem 'shoulda-matchers'
gem 'autotest-rails'
gem 'ffaker'
gem 'webmock'
gem 'vcr'
gem 'capybara'
gem 'json_spec'
gem 'simplecov', require: false
gem 'simplecov-sublime-ruby-coverage', require: false
gem 'test_after_commit'
end
What can be wrong with doorkeeper?

ActiveAttr stops working on production server

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...

Resources