NoMethodError (undefined method `new' for nil:NilClass): when try to create Photo object - paperclip

When I try to assign the data sent with the POST method to an object I get the following error.
Started POST "/backend/photos" for 127.0.0.1 at 2012-02-10 19:24:48 +0100
Processing by Backend::PhotosController#create as */*
Parameters: {"utf8"=>"✓", "authenticity_token"=>"yeFZOu6sG3tyNqT4uBb5Xq0fp+1yTZ2wxn0WFPvGhPw=", "photo"=>{"source_type"=>"post", "source_id"=>"5", "cropping"=>"1", "img"=>#<ActionDispatch::Http::UploadedFile:0x00000004798020 #original_filename="p028.jpg", #content_type="image/jpeg", #headers="Content-Disposition: form-data; name=\"photo[img]\"; filename=\"p028.jpg\"\r\nContent-Type: image/jpeg\r\n", #tempfile=#<File:/tmp/RackMultipart20120210-27534-1yyq97g>>}}
Completed 500 Internal Server Error in 1ms
NoMethodError (undefined method `new' for nil:NilClass):
app/controllers/backend/photos_controller.rb:5:in `new'
app/controllers/backend/photos_controller.rb:5:in `create'
Rendered /usr/local/rvm/gems/ruby-1.9.2-p290/gems/actionpack-3.2.1/lib/action_dispatch/middleware/templates/rescues/_trace.erb (2.6ms)
Rendered /usr/local/rvm/gems/ruby-1.9.2-p290/gems/actionpack-3.2.1/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb (1.0ms)
Rendered /usr/local/rvm/gems/ruby-1.9.2-p290/gems/actionpack-3.2.1/lib/action_dispatch/middleware/templates/rescues/diagnostics.erb within rescues/layout (5.3ms)
In controller:
# -*- encoding : utf-8 -*-
class Backend::PhotosController < Backend::BaseController
def create
#photo = Photo.new(params[:photo])
if #photo.save
render :json => { :pic_path => #photo.img.url.to_s , :name => #photo.img.instance.attributes["img_file_name"] }, :content_type => 'text/html'
else
#todo handle error
render :json => { :result => 'error'}, :content_type => 'text/html'
end
end
In model:
# -*- encoding : utf-8 -*-
class Photo < ActiveRecord::Base
scope :previous, lambda {|p| where("id < ? ", p.id).order(" id desc ").limit(1) }
scope :next, lambda {|p| where("id > ? ", p.id).order(" id asc ").limit(1) }
after_save :observe_seq_after_save
before_create :set_seq_before_create
after_update :change_seq_after_update
after_destroy :change_seq_after_destroy
attr_accessor :cropping
belongs_to :product
after_update :reprocess_picture, :if => :cropping?
has_attached_file :img, :styles => {
:thumb => { :geometry => '130x130#', :quality => 60, :format => 'JPG', :processors => [:cropper]},
:normal => { :geometry => '520x520>', :quality => 90, :format => 'JPG'},
:big => { :geometry => '800x600>', :quality => 90, :format => 'JPG'}
}
validates_attachment_presence :img
validates_attachment_size :img, :less_than => 5.megabytes
validates_attachment_content_type :img, :content_type => [ 'image/jpeg', 'image/png', 'image/pjpeg' ]
In routes:
namespace :backend do
root :to => "dashboards#show"
match "/set_per_page_admin" => "sessions#set_per_page_admin"
match "/posts/:post_id/photos/:id/move_up" => "photos#move_up"
match "/posts/:post_id/photos/:id/move_down" => "photos#move_down"
match "/photos/reset_seq" => "photos#reset_seq"
match "/photos/new/:source_type/:source_id" => "photos#new"
resources :photos do
member do
get :crop
get :crop_existing_photo
end
end
scope "/remote" do
match "/show_pic" => "photos#show_pic"
match "/show_crop" => "photos#show_crop"
end
resources :posts
end
Installed gems:
Gems included by the bundle:
* actionmailer (3.2.1)
* actionpack (3.2.1)
* activemodel (3.2.1)
* activerecord (3.2.1)
* activeresource (3.2.1)
* activesupport (3.2.1)
* arel (3.0.0)
* builder (3.0.0)
* bundler (1.0.21)
* cocaine (0.2.1)
* coffee-rails (3.2.2)
* coffee-script (2.2.0)
* coffee-script-source (1.2.0)
* date_validator (0.6.3)
* erubis (2.7.0)
* execjs (1.3.0)
* foreigner (1.1.1)
* hike (1.2.1)
* i18n (0.6.0)
* journey (1.0.1)
* jquery-rails (2.0.0)
* json (1.6.5)
* libv8 (3.3.10.4)
* magic_encoding (0.0.2)
* mail (2.4.1)
* mime-types (1.17.2)
* multi_json (1.0.4)
* mysql2 (0.3.11)
* paperclip (2.6.0 71d3f46)
* polyglot (0.3.3)
* rack (1.4.1)
* rack-cache (1.1)
* rack-ssl (1.3.2)
* rack-test (0.6.1)
* rails (3.2.1)
* railties (3.2.1)
* rake (0.9.2.2)
* rdoc (3.12)
* rmagick (2.12.0)
* sass (3.1.15)
* sass-rails (3.2.4)
* sprockets (2.1.2)
* stringex (1.3.0)
* therubyracer (0.9.9)
* thor (0.14.6)
* tilt (1.3.3)
* treetop (1.4.10)
* tzinfo (0.3.31)
* uglifier (1.2.3)
* will_paginate (3.0.3)
It is interesting that in another project the same code works well. Gems in this project:
* actionmailer (3.1.0.rc8)
* actionpack (3.1.0.rc8)
* activemodel (3.1.0.rc8)
* activerecord (3.1.0.rc8)
* activeresource (3.1.0.rc8)
* activesupport (3.1.0.rc8)
* addressable (2.2.6)
* arel (2.2.1)
* authlogic (3.1.0)
* aws-s3 (0.6.2)
* bcrypt-ruby (3.0.1)
* builder (3.0.0)
* bundler (1.0.21)
* date_validator (0.6.3)
* devise (1.5.3)
* erubis (2.7.0)
* execjs (1.3.0)
* foreigner (1.1.1)
* heroku (2.18.1)
* hike (1.2.1)
* i18n (0.6.0)
* jquery-rails (1.0.19)
* json (1.6.5)
* launchy (2.0.5)
* libv8 (3.3.10.4)
* magic_encoding (0.0.2)
* mail (2.3.0)
* mime-types (1.17.2)
* multi_json (1.0.4)
* mysql2 (0.3.11)
* nifty-generators (0.4.6)
* orm_adapter (0.0.6)
* paperclip (2.3.6)
* polyglot (0.3.3)
* rack (1.3.3)
* rack-cache (1.0.3)
* rack-mount (0.8.3)
* rack-ssl (1.3.2)
* rack-test (0.6.1)
* rails (3.1.0.rc8)
* rails-i18n (0.3.0)
* rails3-jquery-autocomplete (1.0.5)
* railties (3.1.0.rc8)
* rake (0.9.2.2)
* rdoc (3.12)
* rest-client (1.6.7)
* rmagick (2.12.0)
* rubyzip (0.9.5)
* sprockets (2.0.3)
* stringex (1.3.0)
* term-ansicolor (1.0.7)
* therubyracer (0.9.9)
* thor (0.14.6)
* tilt (1.3.3)
* treetop (1.4.10)
* tzinfo (0.3.31)
* uglifier (1.2.2)
* warden (1.1.0)
* will_paginate (3.0.2)
* xml-simple (1.1.1)
I added a gem 'aws-sdk', but it did not help anything.
Migration file:
class CreatePhotos < ActiveRecord::Migration
def self.up
create_table :photos do |t|
t.string :source_type, :null => true
t.integer :source_id, :null => true
t.integer :seq
t.string :img_file_name
t.string :img_content_type
t.integer :img_file_size
t.datetime :img_updated_at
t.string :title, :null => true
t.text :desc, :limit=>400, :null=>true
t.string :meta_title, :default => nil
t.string :meta_desc, :default => nil
t.string :meta_keywords, :default => nil
t.timestamps
end
add_index(:photos, :source_id)
add_index(:photos, :source_type)
add_index(:photos, :seq)
end
def self.down
drop_table :photos
end
end
I have no ideas to solve this problem. Thanks for any help

Related

Rails 5 Faraday connection for Facebook Omniauth

I have tried all the tricks in the book and all the possible solution in stack over flow.But still couldn't figure out the problem. The program pauses at the call back initiated stage and shows faraday connection : timed out. I have the following code:
gem 'omniauth', '~> 1.3', '>= 1.3.1'
gem 'omniauth-facebook'
Routes.rb
devise_for :users,
:path => '',
:path_names => {:sign_in => 'login', :sign_out => 'logout', :edit => 'profile' },
:controllers => {:omniauth_callbacks => 'omniauth_callbacks'}
/Controller.rb
class OmniauthCallbacksController < Devise::OmniauthCallbacksController
def facebook
#user = User.from_omniauth(request.env["omniauth.auth"])
if #user.persisted?
sign_in_and_redirect #user, :event => :authentication
set_flash_message(:notice, :success, :kind => "Facebook") if is_navigational_format?
else
session["devise.facebook_data"] = request.env["omniauth.auth"].except("extra")
redirect_to new_user_registration_url
end
end
end
/user.rb
class User < ApplicationRecord
def self.from_omniauth(auth)
user = User.where(email: auth.info.email).first
if user
return user
else
where(provider: auth.provider, uid: auth.uid).first_or_create do |user|
user.provider = auth.provider
user.uid = auth.uid
user.email = auth.info.email
user.image = auth.info.image
user.password = Devise.friendly_token[0,20]
user.firstname = auth.info.first_name
user.lastname = auth.info.last_name
user.phonenumber == '0000000000'
user.tc == true
user.year == true
end
end
end
end
/devise.rb
config.omniauth:facebook,ENV['FACEBOOK_ID'],ENV['FACEBOOK_SECRET'],scope:'email',info_fields:'email,first_name,last_name'

private method `split' called for nil:NilClass

I'm using the sitemap_generator (https://github.com/kjvarga/sitemap_generator) gem and seem to have my code working fine in the development environment but when I try to run it in production I get the following error:
private method `split' called for nil:NilClass
This only happens in the production environment (both on my machine and my production server), everything runs fine in development. Here's my site map code which resides in config/sitemap.rb:
SitemapGenerator::Sitemap.default_host = "https://www.mysite.com"
SitemapGenerator::Sitemap.create do
# The root path '/' and sitemap index file are added automatically for you.
# Links are added to the Sitemap in the order they are specified.
add '/classifieds', :changefreq => 'yearly', :priority => 0.75, :lastmod => '2013-01-01'
add '/sell_modified_cars', :changefreq => 'yearly', :priority => 0.75, :lastmod => '2013-01-01'
add '/sell_race_cars', :changefreq => 'yearly', :priority => 0.75, :lastmod => '2013-01-01'
add '/motorsport_event/organizations', :changefreq => 'monthly', :priority => 0.8, :lastmod => Organization.last.created_at
Organization.find_each do |org|
add motorsport_event_organization_path(org), :changefreq => 'daily', :priority => 0.9, :lastmod => Time.now
end
Event.find_each do |event|
add motorsport_event_organization_event_path(event.organization, event), :changefreq => 'daily', :priority => 1, :lastmod => event.event_date
end
Listing.active.each do |listing|
add classifieds_listing_path(listing), :changefreq => 'daily', :priority => 1, :lastmod => listing.updated_at
end
add '/faq', :changefreq => 'monthly', :priority => 0.5, :lastmod => '2013-07-01'
add '/how_it_works_for_buyers', :changefreq => 'yearly', :priority => 0.5, :lastmod => '2013-01-01'
add '/how_it_works_for_sellers', :changefreq => 'yearly', :priority => 0.5, :lastmod => '2013-01-01'
add '/buyer_faq', :changefreq => 'yearly', :priority => 0.5, :lastmod => '2013-01-01'
add '/seller_faq', :changefreq => 'yearly', :priority => 0.5, :lastmod => '2013-01-01'
add '/search', :changefreq => 'yearly', :priority => 0.5, :lastmod => '2013-01-01'
############
# PARTNERS #
############
add '/', :changefreq => 'monthly', :priority => 0.9, :lastmod => '2013-07-01', :host => 'https://partners.mysite.com'
add '/blogs', :changefreq => 'monthly', :priority => 0.8, :lastmod => Blog.last.created_at, :host => 'https://partners.mysite.com'
Blog.find_each do |blog|
add partners_blog_path(blog), :priority => 1, :lastmod => Blog.last.created_at, :host => 'https://partners.mysite.com'
end
add '/pricing', :changefreq => 'monthly', :priority => 0.8, :lastmod => '2013-07-01', :host => 'https://partners.mysite.com'
add '/faq', :changefreq => 'monthly', :priority => 0.5, :lastmod => '2013-07-01', :host => 'https://partners.mysite.com'
add '/whoweare', :changefreq => 'yearly', :priority => 0.5, :lastmod => '2012-01-01', :host => 'https://partners.mysite.com'
add '/workwithus', :changefreq => 'monthly', :priority => 0.5, :lastmod => '2012-01-01', :host => 'https://partners.mysite.com'
add '/contactus', :priority => 0.5, :lastmod => '2012-01-01', :host => 'https://partners.mysite.com'
end
When I run the rake task in the production environment I get the error noted above. Here's the whole stack trace:
rake sitemap:refresh --trace
** Invoke sitemap:refresh (first_time)
** Invoke sitemap:create (first_time)
** Invoke sitemap:require_environment (first_time)
** Execute sitemap:require_environment
** Invoke environment (first_time)
** Execute environment
** Execute sitemap:create
rake aborted!
private method `split' called for nil:NilClass
/shared/bundled_gems/ruby/1.8/gems/subdomain-fu-0.5.4/lib/subdomain-fu.rb:65:in `host_without_subdomain'
/shared/bundled_gems/ruby/1.8/gems/subdomain-fu-0.5.4/lib/subdomain-fu.rb:85:in `change_subdomain_of_host'
/shared/bundled_gems/ruby/1.8/gems/subdomain-fu-0.5.4/lib/subdomain-fu.rb:72:in `rewrite_host_for_subdomains'
/shared/bundled_gems/ruby/1.8/gems/subdomain-fu-0.5.4/lib/subdomain_fu/url_rewriter.rb:6:in `url_for'
(eval):17:in `motorsport_event_organization_path'
/releases/20130720225723/config/sitemap.rb:13:in `run'
/shared/bundled_gems/ruby/1.8/gems/activerecord-2.3.16/lib/active_record/batches.rb:26:in `find_each'
/shared/bundled_gems/ruby/1.8/gems/activerecord-2.3.16/lib/active_record/batches.rb:26:in `each'
/shared/bundled_gems/ruby/1.8/gems/activerecord-2.3.16/lib/active_record/batches.rb:26:in `find_each'
/shared/bundled_gems/ruby/1.8/gems/activerecord-2.3.16/lib/active_record/batches.rb:66:in `find_in_batches'
/shared/bundled_gems/ruby/1.8/gems/activerecord-2.3.16/lib/active_record/batches.rb:25:in `find_each'
/releases/20130720225723/config/sitemap.rb:12:in `run'
/shared/bundled_gems/ruby/1.8/gems/sitemap_generator-4.1.1/lib/sitemap_generator/interpreter.rb:59:in `instance_eval'
/shared/bundled_gems/ruby/1.8/gems/sitemap_generator-4.1.1/lib/sitemap_generator/interpreter.rb:59:in `eval'
/shared/bundled_gems/ruby/1.8/gems/sitemap_generator-4.1.1/lib/sitemap_generator/link_set.rb:39:in `create'
/shared/bundled_gems/ruby/1.8/gems/sitemap_generator-4.1.1/lib/sitemap_generator.rb:33:in `send'
/shared/bundled_gems/ruby/1.8/gems/sitemap_generator-4.1.1/lib/sitemap_generator.rb:33:in `method_missing'
/releases/20130720225723/config/sitemap.rb:2:in `run'
/shared/bundled_gems/ruby/1.8/gems/sitemap_generator-4.1.1/lib/sitemap_generator/tasks.rb:51
/shared/bundled_gems/ruby/1.8/gems/rake-0.8.7/lib/rake.rb:636:in `call'
/shared/bundled_gems/ruby/1.8/gems/rake-0.8.7/lib/rake.rb:636:in `execute'
/shared/bundled_gems/ruby/1.8/gems/rake-0.8.7/lib/rake.rb:631:in `each'
/shared/bundled_gems/ruby/1.8/gems/rake-0.8.7/lib/rake.rb:631:in `execute'
/shared/bundled_gems/ruby/1.8/gems/rake-0.8.7/lib/rake.rb:597:in `invoke_with_call_chain'
/usr/lib/ruby/1.8/monitor.rb:242:in `synchronize'
/shared/bundled_gems/ruby/1.8/gems/rake-0.8.7/lib/rake.rb:590:in `invoke_with_call_chain'
/shared/bundled_gems/ruby/1.8/gems/rake-0.8.7/lib/rake.rb:607:in `invoke_prerequisites'
/shared/bundled_gems/ruby/1.8/gems/rake-0.8.7/lib/rake.rb:604:in `each'
/shared/bundled_gems/ruby/1.8/gems/rake-0.8.7/lib/rake.rb:604:in `invoke_prerequisites'
/shared/bundled_gems/ruby/1.8/gems/rake-0.8.7/lib/rake.rb:596:in `invoke_with_call_chain'
/usr/lib/ruby/1.8/monitor.rb:242:in `synchronize'
/shared/bundled_gems/ruby/1.8/gems/rake-0.8.7/lib/rake.rb:590:in `invoke_with_call_chain'
/shared/bundled_gems/ruby/1.8/gems/rake-0.8.7/lib/rake.rb:583:in `invoke'
/shared/bundled_gems/ruby/1.8/gems/rake-0.8.7/lib/rake.rb:2051:in `invoke_task'
/shared/bundled_gems/ruby/1.8/gems/rake-0.8.7/lib/rake.rb:2029:in `top_level'
/shared/bundled_gems/ruby/1.8/gems/rake-0.8.7/lib/rake.rb:2029:in `each'
/shared/bundled_gems/ruby/1.8/gems/rake-0.8.7/lib/rake.rb:2029:in `top_level'
/shared/bundled_gems/ruby/1.8/gems/rake-0.8.7/lib/rake.rb:2068:in `standard_exception_handling'
/shared/bundled_gems/ruby/1.8/gems/rake-0.8.7/lib/rake.rb:2023:in `top_level'
/shared/bundled_gems/ruby/1.8/gems/rake-0.8.7/lib/rake.rb:2001:in `run'
/shared/bundled_gems/ruby/1.8/gems/rake-0.8.7/lib/rake.rb:2068:in `standard_exception_handling'
/shared/bundled_gems/ruby/1.8/gems/rake-0.8.7/lib/rake.rb:1998:in `run'
/shared/bundled_gems/ruby/1.8/gems/rake-0.8.7/bin/rake:31
/shared/bundled_gems/ruby/1.8/bin/rake:19:
I can't find anything different between production and development that would cause this. Any help you could provide would be appreciated!
EDIT: I should probably add that this seems to be something wrong with generating the paths. Removing all of the paths makes this work fine. The problem is that the paths are correct and this code runs fine in development. I don't know why the paths don't generate in production.
EDIT 2: Here's development.rb:
require 'rack/ssl-enforcer'
require 'stripe'
config.middleware.use ::Rack::SslEnforcer, :except => /^\/api\//
# Settings specified here will take precedence over those in config/environment.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 webserver 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.action_controller.consider_all_requests_local = true
config.action_view.debug_rjs = true
config.action_controller.perform_caching = false
# Don't care if the mailer can't send
config.action_mailer.raise_delivery_errors = false
config.after_initialize do
ActionMailer::Base.delivery_method = :amazon_ses
ActionMailer::Base.custom_amazon_ses_mailer = AWS::SES::Base.new(:secret_access_key => S3_CONFIG[:secret_access_key], :access_key_id => S3_CONFIG[:access_key_id])
end
# Default APP Domain
APP_DOMAIN = 'mysite.dev'
ActionMailer::Base.default_url_options[:host] = APP_DOMAIN
# ensure the sessions work across the subdomains
begin
config.action_controller.session[:domain] = ".#{APP_DOMAIN}"
rescue
config.action_controller.session = {:domain => ".#{APP_DOMAIN}"}
end
Here's production.rb:
# Settings specified here will take precedence over those in config/environment.rb
require 'rack/ssl-enforcer'
require 'stripe'
config.middleware.use ::Rack::SslEnforcer, :except => /^\/api\//
# The production environment is meant for finished, "live" apps.
# Code is not reloaded between requests
config.cache_classes = true
# Full error reports are disabled and caching is turned on
config.action_controller.consider_all_requests_local = false
config.action_controller.perform_caching = true
config.action_view.cache_template_loading = true
# See everything in the log (default is :info)
# config.log_level = :debug
# Use a different logger for distributed setups
# config.logger = SyslogLogger.new
# Use a different cache store in production
# config.cache_store = :mem_cache_store
# Enable serving of images, stylesheets, and javascripts from an asset server
# config.action_controller.asset_host = "http://assets.example.com"
# Disable delivery errors, bad email addresses will be ignored
config.action_mailer.raise_delivery_errors = false
# Enable threaded mode
# config.threadsafe!
# Default APP Domain
APP_DOMAIN = 'mysite.com'
ActionMailer::Base.default_url_options[:host] = "www.#{APP_DOMAIN}"
# Amazon SES Mailer
config.after_initialize do
ActionMailer::Base.delivery_method = :amazon_ses
ActionMailer::Base.custom_amazon_ses_mailer = AWS::SES::Base.new(:secret_access_key => S3_CONFIG[:secret_access_key], :access_key_id => S3_CONFIG[:access_key_id])
end
# ensure the sessions work across the subdomains
begin
config.action_controller.session[:domain] = ".#{APP_DOMAIN}"
rescue
config.action_controller.session = {:domain => ".#{APP_DOMAIN}"}
end
The prod and dev environments do not share a DB.
The issue here is that since you're running the rake task outside of the context of a request, there is no host for it to operate on. From the source:
The exception occurs at: https://github.com/mbleigh/subdomain-fu/blob/v0.5.4/lib/subdomain-fu.rb#L65
We can see that it's trying to split a nil host. Following the stack trace to: https://github.com/mbleigh/subdomain-fu/blob/v0.5.4/lib/subdomain_fu/url_rewriter.rb#L6
We see that the host being passed in is
options[:host] || default_url_options[:host]
Normally, default_url_options[:host] would be populated from the request's Host header, but since this is outside of a request, there's no host header to operate on. What you need to do is either:
Set a default host via overriding default_url_options in your application controller: http://guides.rubyonrails.org/action_controller_overview.html#default-url-options
Or, pass in :host to the route options from where you're calling motorsport_event_organization_path.
The first option is probably the easiest.
The error will go away if you define:
def nil.split
tap { warn "Stand back, splitting nil!" }
end

In Datamapper, getting "NoMethodError - undefined method `get!' for nil:NilClass:"

I have two tables, mapped out for datamapper:
class User
include DataMapper::Resource
property :id, Serial, :field => 'ID'
property :user_first_name, String, :field => "USER_FIRST_NAME"
property :user_last_name, String, :field => "USER_LAST_NAME"
has n, :login_sessions, :child_key => [ :user_id ], :parent_key => [ :id ]
end
and
class LoginSession
include DataMapper::Resource
property :id, Serial, :field => 'ID'
property :user_id, Integer, :field => "USER_ID"
property :login_time, DateTime, :field => "LOGIN_TIME"
belongs_to :user, :parent_key => [ :user_id ], :child_key => [ :id ]
end
Given a LoginSession object, I want to get the corresponding user:
session = LoginSession.first(:id => 1)
if session
# code reaches here, meaning that session is not nil.
user = session.user
end
When I run this code, at user = session.user, I get the following error:
NoMethodError - undefined method `get!' for nil:NilClass:
/Users/Tom/.rvm/gems/ruby-1.9.3-p362/gems/dm-core-1.2.0/lib/dm- core/property_set.rb:88:in `block in get!'
/Users/Tom/.rvm/gems/ruby-1.9.3-p362/gems/dm-core-1.2.0/lib/dm-core/support/subject_set.rb:210:in `block in each'
/Users/Tom/.rvm/gems/ruby-1.9.3-p362/gems/dm-core-1.2.0/lib/dm-core/support/ordered_set.rb:319:in `block in each'
/Users/Tom/.rvm/gems/ruby-1.9.3-p362/gems/dm-core-1.2.0/lib/dm-core/support/ordered_set.rb:319:in `each'
/Users/Tom/.rvm/gems/ruby-1.9.3-p362/gems/dm-core-1.2.0/lib/dm-core/support/ordered_set.rb:319:in `each'
/Users/Tom/.rvm/gems/ruby-1.9.3-p362/gems/dm-core-1.2.0/lib/dm-core/support/subject_set.rb:210:in `each'
/Users/Tom/.rvm/gems/ruby-1.9.3-p362/gems/dm-core-1.2.0/lib/dm-core/property_set.rb:88:in `map'
/Users/Tom/.rvm/gems/ruby-1.9.3-p362/gems/dm-core-1.2.0/lib/dm-core/property_set.rb:88:in `get!'
/Users/Tom/.rvm/gems/ruby-1.9.3-p362/gems/dm-core-1.2.0/lib/dm-core/associations/many_to_one.rb:289:in `source_key_different?'
/Users/Tom/.rvm/gems/ruby-1.9.3-p362/gems/dm-core-1.2.0/lib/dm-core/associations/many_to_one.rb:179:in `lazy_load'
/Users/Tom/.rvm/gems/ruby-1.9.3-p362/gems/dm-core-1.2.0/lib/dm-core/resource/persistence_state/persisted.rb:23:in `lazy_load'
/Users/Tom/.rvm/gems/ruby-1.9.3-p362/gems/dm-core-1.2.0/lib/dm-core/resource/persistence_state/persisted.rb:8:in `get'
/Users/Tom/.rvm/gems/ruby-1.9.3-p362/gems/dm-core-1.2.0/lib/dm-core/model/relationship.rb:340:in `user'
/Users/Tom/Projects/api_server/app.rb:197:in `block in <class:MyApp>'
...
I can't figure out what I'm doing wrong. I'm assuming that the LoginSession object can't find a corresponding user method or something? Please help!

I18n.translate(:countries) doesnt return countries for some locales

I have a very strange issue. I have 6 locales (en, ca, es, es_PE, es_MX, es_Cl)
If i type I18n.translate(:countries) It returns the countries for some locales and other locales it returns: "translation missing: es-PE.countries"
I have 6 country files in config/locales called:
localized_country_select.es.rb
localized_country_select.es_MX.rb
localized_country_select.es_PE.rb
localized_country_select.en.rb
etc etc
This all occurred after a bundle update and I cant find some errors in the localized country files. I even tested it in a new app and the localized country files worked just fine.
This issue was bugging me a couple of hours yesterday and really no clue... A little help would be highly appreciated.
Some info:
Gemfile:
source 'http://rubygems.org'
gem 'rails', '~> 3.1.2'
gem 'rack', '~> 1.3.5'
gem 'puma'
group :production do
gem 'unicorn'
end
gem 'bcrypt-ruby', '~> 3.0.0'
gem 'yajl-ruby' # Speedy JSON
gem 'couchrest_model', git: 'https://github.com/samlown/couchrest_model.git'
# Asset template engines
group 'assets' do
gem 'sass-rails', '3.1.4'
gem 'haml-rails'
gem 'coffee-script'
gem 'uglifier'
gem "compass-rails"
end
gem 'jquery-rails'
gem 'therubyracer', :require => false
gem 'geokit'
gem 'geocoder'
gem 'pr_geohash'
gem 'roadie'
gem "gravatar", "~> 1.0"
# SMS related gubbins
gem "e164"
gem "textmagic"
gem 'formtastic'
# Handle money gracefully
gem 'money', '~> 5.0.0'
# For exchange rates
gem 'money-open-exchange-rates', git: "git://github.com/MaxiMobility/money-open-exchange-rates.git"
gem 'state_machine'
gem 'airbrake'
gem 'adyen'
gem 'spreadsheet'
gem 'gettext_i18n_rails'
gem 'localized_country_select', :git => 'https://github.com/samlown/localized_country_select.git', :branch => 'master'
gem 'bluecloth'
gem 'resque', :require => 'resque/server'
gem 'resque_mailer'
gem 'resque-timeout'
gem 'aws-ses', :require => 'aws/ses'#, :git => "http://github.com/teeparham/aws-ses.git", :ref => "eca27d0517"
gem 'twitter'
gem 'kaminari'
gem 'carrierwave'
gem 'fog'
gem 'mini_magick'
gem 'prawn'
gem 'useragent'
# Authorization
gem 'cancan'
# Solves the pain of uploading files + AJAX
gem "remotipart"
gem 'whenever', :require => false
group :development do
gem 'web_translate_it', :require => false
gem 'nifty-generators'
gem 'rspec-rails', '~> 2.6'
gem 'thin'
gem 'debugger'
# Deployments
gem 'capistrano'
gem 'capistrano-ext'
gem "capistrano_rsync_with_remote_cache", "~> 2.4.0"
# Used for compiling .po and .mo files
gem 'gettext', '>=1.9.3', :require => false
gem 'ruby_parser', :require => false
# Used by localised_country_select to import languages
gem 'hpricot'
# Testing javascript
gem "jasminerice"
gem 'headless'
end
group :test do
# Pretty printed test output
gem 'turn', :require => false
gem 'steak'
gem 'rack-test'
gem 'rspec'
gem 'factory_girl_rails'
gem 'autotest'
gem 'rspec-rails', '~> 2.6'
gem 'guard-rspec'
gem 'capybara'
# Ensure QT kit is installed: brew install qt
gem 'capybara-webkit'
gem 'launchy'
# Avoid RubyGems 1.8 issues with this gem:
gem 'ZenTest', '~> 4.5.0'
# Testing javascript
gem "jasminerice"
end
This is the diff of my bundle update (biggest change is Rails 3.1.8).
Gemfile:
-gem 'rails', '3.1.2'
+gem 'rails', '~> 3.1.2'
group 'assets' do
- gem 'sass-rails'
+ gem 'sass-rails', '3.1.4'
end
Gemfile.lock
- Ascii85 (1.0.1)
+ Ascii85 (1.0.2)
+ actionmailer (3.1.8)
+ actionpack (= 3.1.8)
+ mail (~> 2.3.3)
+ actionpack (3.1.8)
+ activemodel (= 3.1.8)
+ activesupport (= 3.1.8)
- rack (~> 1.3.5)
- rack-cache (~> 1.1)
+ rack (~> 1.3.6)
+ rack-cache (~> 1.2)
- sprockets (~> 2.1.0)
- activemodel (3.1.2)
- activesupport (= 3.1.2)
+ sprockets (~> 2.0.4)
+ activemodel (3.1.8)
+ activesupport (= 3.1.8)
- activerecord (3.1.2)
- activemodel (= 3.1.2)
- activesupport (= 3.1.2)
- arel (~> 2.2.1)
+ activerecord (3.1.8)
+ activemodel (= 3.1.8)
+ activesupport (= 3.1.8)
+ arel (~> 2.2.3)
- activeresource (3.1.2)
- activemodel (= 3.1.2)
- activesupport (= 3.1.2)
- activesupport (3.1.2)
- multi_json (~> 1.0)
- addressable (2.2.8)
- adyen (1.3.0)
- airbrake (3.0.5)
- activesupport
+ activeresource (3.1.8)
+ activemodel (= 3.1.8)
+ activesupport (= 3.1.8)
+ activesupport (3.1.8)
+ multi_json (>= 1.0, < 1.3)
+ addressable (2.3.2)
+ adyen (1.3.1)
+ airbrake (3.1.4)
- ansi (1.3.0)
+ girl_friday
+ ansi (1.4.3)
- cancan (1.6.7)
- capistrano (2.11.2)
+ cancan (1.6.8)
+ capistrano (2.13.4)
- capybara (1.1.1)
+ capybara (1.1.2)
- capybara-webkit (0.12.0)
+ capybara-webkit (0.12.1)
- chunky_png (1.2.5)
+ chunky_png (1.2.6)
- coffee-script-source (1.1.2)
+ coffee-script-source (1.3.3)
+ connection_pool (0.9.2)
- debugger (1.1.3)
+ debugger (1.2.0)
- debugger-ruby_core_source (~> 1.1.2)
- debugger-linecache (1.1.1)
+ debugger-ruby_core_source (~> 1.1.3)
+ debugger-linecache (1.1.2)
- debugger-ruby_core_source (1.1.2)
+ debugger-ruby_core_source (1.1.3)
- e164 (0.3.1)
+ e164 (0.3.2)
- execjs (1.2.9)
+ execjs (1.4.0)
- factory_girl (2.3.0)
- activesupport
- factory_girl_rails (1.4.0)
- factory_girl (~> 2.3.0)
+ factory_girl (4.1.0)
+ activesupport (>= 3.0.0)
+ factory_girl_rails (4.1.0)
+ factory_girl (~> 4.1.0)
- fast_gettext (0.6.2)
+ fast_gettext (0.6.10)
- fog (1.5.0)
+ fog (1.6.0)
- formtastic (2.2.0)
+ formtastic (2.2.1)
- geocoder (1.1.0)
- geokit (1.6.0)
- gettext (2.1.0)
- locale (>= 2.0.5)
- gettext_i18n_rails (0.3.0)
- fast_gettext
+ geocoder (1.1.3)
+ geokit (1.6.5)
+ multi_json
+ gettext (2.3.1)
+ locale
+ gettext_i18n_rails (0.7.1)
+ fast_gettext (>= 0.4.8)
+ girl_friday (0.10.0)
+ connection_pool (~> 0.9.0)
- guard (1.0.0)
- ffi (>= 0.5.0)
- thor (~> 0.14.6)
- guard-rspec (0.6.0)
- guard (>= 0.10.0)
+ guard (1.3.2)
+ listen (>= 0.4.2)
+ thor (>= 0.14.6)
+ guard-rspec (1.2.1)
+ guard (>= 1.1)
+ hashery (2.0.1)
- highline (1.6.11)
+ highline (1.6.15)
- httparty (0.8.1)
- multi_json
+ httparty (0.9.0)
+ multi_json (~> 1.0)
- kaminari (0.12.4)
- rails (>= 3.0.0)
+ kaminari (0.14.1)
+ actionpack (>= 3.0.0)
+ activesupport (>= 3.0.0)
- launchy (2.0.5)
- addressable (~> 2.2.6)
+ launchy (2.1.2)
+ addressable (~> 2.3)
- locale (2.0.5)
+ listen (0.5.1)
+ locale (2.0.8)
- mini_magick (3.3)
- subexec (~> 0.1.0)
- mocha (0.10.0)
+ mini_magick (3.4)
+ subexec (~> 0.2.1)
+ mocha (0.12.4)
- multi_json (1.3.6)
+ multi_json (1.2.0)
- pdf-reader (1.0.0)
+ pdf-reader (1.2.0)
+ hashery (~> 2.0)
- puma (1.6.2)
+ puma (1.6.3)
- rails (3.1.2)
- actionmailer (= 3.1.2)
- actionpack (= 3.1.2)
- activerecord (= 3.1.2)
- activeresource (= 3.1.2)
- activesupport (= 3.1.2)
+ rails (3.1.8)
+ actionmailer (= 3.1.8)
+ actionpack (= 3.1.8)
+ activerecord (= 3.1.8)
+ activeresource (= 3.1.8)
+ activesupport (= 3.1.8)
- railties (= 3.1.2)
- railties (3.1.2)
- actionpack (= 3.1.2)
- activesupport (= 3.1.2)
+ railties (= 3.1.8)
+ railties (3.1.8)
+ actionpack (= 3.1.8)
+ activesupport (= 3.1.8)
- redis (2.2.2)
- redis-namespace (1.0.3)
- redis (< 3.0.0)
+ redis (3.0.1)
+ redis-namespace (1.2.1)
+ redis (~> 3.0.0)
- resque (1.20.0)
+ resque (1.22.0)
- redis-namespace (~> 1.0.2)
+ redis-namespace (~> 1.0)
- resque_mailer (2.0.2)
- actionmailer (>= 3.0.0)
- resque (>= 1.2.3)
+ resque_mailer (2.1.0)
+ actionmailer (~> 3.0)
- rspec (2.8.0)
- rspec-core (~> 2.8.0)
- rspec-expectations (~> 2.8.0)
- rspec-mocks (~> 2.8.0)
- rspec-core (2.8.0)
- rspec-expectations (2.8.0)
- diff-lcs (~> 1.1.2)
- rspec-mocks (2.8.0)
- rspec-rails (2.8.1)
+ rspec (2.11.0)
+ rspec-core (~> 2.11.0)
+ rspec-expectations (~> 2.11.0)
+ rspec-mocks (~> 2.11.0)
+ rspec-core (2.11.1)
+ rspec-expectations (2.11.3)
+ diff-lcs (~> 1.1.3)
+ rspec-mocks (2.11.2)
+ rspec-rails (2.11.0)
- rspec (~> 2.8.0)
+ rspec (~> 2.11.0)
- ruby-ole (1.2.11.3)
- ruby-rc4 (0.1.3)
+ ruby-ole (1.2.11.4)
+ ruby-rc4 (0.1.5)
- sass-rails (3.1.6)
+ sass-rails (3.1.4)
- sass (>= 3.1.10)
+ sass (>= 3.1.4)
+ sprockets (~> 2.0.0)
- sexp_processor (3.0.7)
+ sexp_processor (3.2.0)
- sinatra (1.3.2)
+ sinatra (1.3.3)
- spreadsheet (0.6.8)
+ spreadsheet (0.7.3)
- sprockets (2.1.3)
+ sprockets (2.0.4)
- state_machine (1.0.2)
+ state_machine (1.1.2)
- subexec (0.1.0)
+ subexec (0.2.2)
- therubyracer (0.9.10)
+ therubyracer (0.10.2)
- turn (0.8.3)
+ turn (0.9.6)
- twitter (3.7.0)
- faraday (~> 0.8)
- multi_json (~> 1.3)
- simple_oauth (~> 0.1.6)
+ twitter (2.2.0)
+ activesupport (>= 2.3.9, < 4)
+ faraday (~> 0.7)
+ multi_json (~> 1.0)
+ simple_oauth (~> 0.1)
- uglifier (1.0.3)
+ uglifier (1.3.0)
- multi_json (>= 1.0.2)
+ multi_json (~> 1.0, >= 1.0.2)
- useragent (0.4.6)
+ useragent (0.4.10)
- web_translate_it (1.10.0)
+ web_translate_it (2.0.4)
+ json
- rails (= 3.1.2)
+ rails (~> 3.1.2)
- sass-rails
+ sass-rails (= 3.1.4)
My locale files:
localized_country.es.rb
#encoding: UTF-8
{ :es_CL => {
:countries => {
:AC => "Isla de la Ascensión",
:AD => "Andorra",
:AE => "Emiratos Árabes Unidos",
:AF => "Afganistán",
:AG => "Antigua y Barbuda",
:AI => "Anguila",
:AL => "Albania",
:AM => "Armenia",
:AN => "Antillas Neerlandesas",
:AO => "Angola",
:AQ => "Antártida",
:AR => "Argentina",
:AS => "Samoa Americana",
:AT => "Austria",
:AU => "Australia",
:AW => "Aruba",
:AX => "Islas Åland",
:AZ => "Azerbaiyán",
:BA => "Bosnia-Herzegovina",
:BB => "Barbados",
:BD => "Bangladesh",
:BE => "Bélgica",
:BF => "Burkina Faso",
:BG => "Bulgaria",
:BH => "Bahréin",
:BI => "Burundi",
:BJ => "Benín",
:BL => "San Bartolomé",
:BM => "Bermudas",
:BN => "Brunéi",
:BO => "Bolivia",
:BQ => "BQ",
:BR => "Brasil",
:BS => "Bahamas",
:BT => "Bután",
:BV => "Isla Bouvet",
:BW => "Botsuana",
:BY => "Bielorrusia",
:BZ => "Belice",
:CA => "Canadá",
:CC => "Islas Cocos",
:CD => "República Democrática del Congo",
:CF => "República Centroafricana",
:CG => "Congo - Brazzaville",
:CH => "Suiza",
:CI => "Costa de Marfil",
:CK => "Islas Cook",
:CL => "Chile",
:CM => "Camerún",
:CN => "China",
:CO => "Colombia",
:CP => "Isla Clipperton",
:CR => "Costa Rica",
:CS => "Serbia y Montenegro",
:CU => "Cuba",
:CV => "Cabo Verde",
:CW => "CW",
:CX => "Isla Christmas",
:CY => "Chipre",
:CZ => "República Checa",
:DE => "Alemania",
:DG => "Diego García",
:DJ => "Yibuti",
:DK => "Dinamarca",
:DM => "Dominica",
:DO => "República Dominicana",
:DZ => "Argelia",
:EA => "Ceuta y Melilla",
:EC => "Ecuador",
:EE => "Estonia",
:EG => "Egipto",
:EH => "Sáhara Occidental",
:ER => "Eritrea",
:ES => "España",
:ET => "Etiopía",
:EU => "Unión Europea",
:FI => "Finlandia",
:FJ => "Fiyi",
:FK => "Islas Malvinas",
:FM => "Micronesia",
:FO => "Islas Feroe",
:FR => "Francia",
:GA => "Gabón",
:GB => "Reino Unido",
:GD => "Granada",
:GE => "Georgia",
:GF => "Guayana Francesa",
:GG => "Guernsey",
:GH => "Ghana",
:GI => "Gibraltar",
:GL => "Groenlandia",
:GM => "Gambia",
:GN => "Guinea",
:GP => "Guadalupe",
:GQ => "Guinea Ecuatorial",
:GR => "Grecia",
:GS => "Islas Georgia del Sur y Sandwich del Sur",
:GT => "Guatemala",
:GU => "Guam",
:GW => "Guinea-Bissau",
:GY => "Guyana",
:HK => "Región Administrativa Especial de Hong Kong de la República Popular China",
:HM => "Islas Heard y McDonald",
:HN => "Honduras",
:HR => "Croacia",
:HT => "Haití",
:HU => "Hungría",
:IC => "Islas Canarias",
:ID => "Indonesia",
:IE => "Irlanda",
:IL => "Israel",
:IM => "Isla de Man",
:IN => "India",
:IO => "Territorio Británico del Océano Índico",
:IQ => "Iraq",
:IR => "Irán",
:IS => "Islandia",
:IT => "Italia",
:JE => "Jersey",
:JM => "Jamaica",
:JO => "Jordania",
:JP => "Japón",
:KE => "Kenia",
:KG => "Kirguistán",
:KH => "Camboya",
:KI => "Kiribati",
:KM => "Comoras",
:KN => "San Cristóbal y Nieves",
:KP => "Corea del Norte",
:KR => "Corea del Sur",
:KW => "Kuwait",
:KY => "Islas Caimán",
:KZ => "Kazajistán",
:LA => "Laos",
:LB => "Líbano",
:LC => "Santa Lucía",
:LI => "Liechtenstein",
:LK => "Sri Lanka",
:LR => "Liberia",
:LS => "Lesoto",
:LT => "Lituania",
:LU => "Luxemburgo",
:LV => "Letonia",
:LY => "Libia",
:MA => "Marruecos",
:MC => "Mónaco",
:MD => "Moldavia",
:ME => "Montenegro",
:MF => "San Martín",
:MG => "Madagascar",
:MH => "Islas Marshall",
:MK => "Macedonia",
:ML => "Mali",
:MM => "Myanmar [Birmania]",
:MN => "Mongolia",
:MO => "Región Administrativa Especial de Macao de la República Popular China",
:MP => "Islas Marianas del Norte",
:MQ => "Martinica",
:MR => "Mauritania",
:MS => "Montserrat",
:MT => "Malta",
:MU => "Mauricio",
:MV => "Maldivas",
:MW => "Malaui",
:MX => "México",
:MY => "Malasia",
:MZ => "Mozambique",
:NA => "Namibia",
:NC => "Nueva Caledonia",
:NE => "Níger",
:NF => "Isla Norfolk",
:NG => "Nigeria",
:NI => "Nicaragua",
:NL => "Países Bajos",
:NO => "Noruega",
:NP => "Nepal",
:NR => "Nauru",
:NU => "Isla Niue",
:NZ => "Nueva Zelanda",
:OM => "Omán",
:PA => "Panamá",
:PE => "Perú",
:PF => "Polinesia Francesa",
:PG => "Papúa Nueva Guinea",
:PH => "Filipinas",
:PK => "Pakistán",
:PL => "Polonia",
:PM => "San Pedro y Miquelón",
:PN => "Islas Pitcairn",
:PR => "Puerto Rico",
:PS => "Territorios Palestinos",
:PT => "Portugal",
:PW => "Palau",
:PY => "Paraguay",
:QA => "Qatar",
:QO => "Territorios alejados de Oceanía",
:RE => "Reunión",
:RO => "Rumanía",
:RS => "Serbia",
:RU => "Rusia",
:RW => "Ruanda",
:SA => "Arabia Saudí",
:SB => "Islas Salomón",
:SC => "Seychelles",
:SD => "Sudán",
:SE => "Suecia",
:SG => "Singapur",
:SH => "Santa Elena",
:SI => "Eslovenia",
:SJ => "Svalbard y Jan Mayen",
:SK => "Eslovaquia",
:SL => "Sierra Leona",
:SM => "San Marino",
:SN => "Senegal",
:SO => "Somalia",
:SR => "Surinam",
:SS => "SS",
:ST => "Santo Tomé y Príncipe",
:SV => "El Salvador",
:SX => "Sint Maarten",
:SY => "Siria",
:SZ => "Suazilandia",
:TA => "Tristán da Cunha",
:TC => "Islas Turcas y Caicos",
:TD => "Chad",
:TF => "Territorios Australes Franceses",
:TG => "Togo",
:TH => "Tailandia",
:TJ => "Tayikistán",
:TK => "Tokelau",
:TL => "Timor Oriental",
:TM => "Turkmenistán",
:TN => "Túnez",
:TO => "Tonga",
:TR => "Turquía",
:TT => "Trinidad y Tobago",
:TV => "Tuvalu",
:TW => "Taiwán",
:TZ => "Tanzania",
:UA => "Ucrania",
:UG => "Uganda",
:UM => "Islas menores alejadas de los Estados Unidos",
:US => "Estados Unidos",
:UY => "Uruguay",
:UZ => "Uzbekistán",
:VA => "Ciudad del Vaticano",
:VC => "San Vicente y las Granadinas",
:VE => "Venezuela",
:VG => "Islas Vírgenes Británicas",
:VI => "Islas Vírgenes de los Estados Unidos",
:VN => "Vietnam",
:VU => "Vanuatu",
:WF => "Wallis y Futuna",
:WS => "Samoa",
:YE => "Yemen",
:YT => "Mayotte",
:ZA => "Sudáfrica",
:ZM => "Zambia",
:ZW => "Zimbabue",
:ZZ => "Región desconocida"
}
}
}
localized_country.es_PE.rb
#encoding: UTF-8
{ :es_PE => {
:countries => {
:AC => "Isla de la Ascensión",
:AD => "Andorra",
:AE => "Emiratos Árabes Unidos",
:AF => "Afganistán",
:AG => "Antigua y Barbuda",
:AI => "Anguila",
:AL => "Albania",
:AM => "Armenia",
:AN => "Antillas Neerlandesas",
:AO => "Angola",
:AQ => "Antártida",
:AR => "Argentina",
:AS => "Samoa Americana",
:AT => "Austria",
:AU => "Australia",
:AW => "Aruba",
:AX => "Islas Åland",
:AZ => "Azerbaiyán",
:BA => "Bosnia-Herzegovina",
:BB => "Barbados",
:BD => "Bangladesh",
:BE => "Bélgica",
:BF => "Burkina Faso",
:BG => "Bulgaria",
:BH => "Bahréin",
:BI => "Burundi",
:BJ => "Benín",
:BL => "San Bartolomé",
:BM => "Bermudas",
:BN => "Brunéi",
:BO => "Bolivia",
:BQ => "BQ",
:BR => "Brasil",
:BS => "Bahamas",
:BT => "Bután",
:BV => "Isla Bouvet",
:BW => "Botsuana",
:BY => "Bielorrusia",
:BZ => "Belice",
:CA => "Canadá",
:CC => "Islas Cocos",
:CD => "República Democrática del Congo",
:CF => "República Centroafricana",
:CG => "Congo - Brazzaville",
:CH => "Suiza",
:CI => "Costa de Marfil",
:CK => "Islas Cook",
:CL => "Chile",
:CM => "Camerún",
:CN => "China",
:CO => "Colombia",
:CP => "Isla Clipperton",
:CR => "Costa Rica",
:CS => "Serbia y Montenegro",
:CU => "Cuba",
:CV => "Cabo Verde",
:CW => "CW",
:CX => "Isla Christmas",
:CY => "Chipre",
:CZ => "República Checa",
:DE => "Alemania",
:DG => "Diego García",
:DJ => "Yibuti",
:DK => "Dinamarca",
:DM => "Dominica",
:DO => "República Dominicana",
:DZ => "Argelia",
:EA => "Ceuta y Melilla",
:EC => "Ecuador",
:EE => "Estonia",
:EG => "Egipto",
:EH => "Sáhara Occidental",
:ER => "Eritrea",
:ES => "España",
:ET => "Etiopía",
:EU => "Unión Europea",
:FI => "Finlandia",
:FJ => "Fiyi",
:FK => "Islas Malvinas",
:FM => "Micronesia",
:FO => "Islas Feroe",
:FR => "Francia",
:GA => "Gabón",
:GB => "Reino Unido",
:GD => "Granada",
:GE => "Georgia",
:GF => "Guayana Francesa",
:GG => "Guernsey",
:GH => "Ghana",
:GI => "Gibraltar",
:GL => "Groenlandia",
:GM => "Gambia",
:GN => "Guinea",
:GP => "Guadalupe",
:GQ => "Guinea Ecuatorial",
:GR => "Grecia",
:GS => "Islas Georgia del Sur y Sandwich del Sur",
:GT => "Guatemala",
:GU => "Guam",
:GW => "Guinea-Bissau",
:GY => "Guyana",
:HK => "Región Administrativa Especial de Hong Kong de la República Popular China",
:HM => "Islas Heard y McDonald",
:HN => "Honduras",
:HR => "Croacia",
:HT => "Haití",
:HU => "Hungría",
:IC => "Islas Canarias",
:ID => "Indonesia",
:IE => "Irlanda",
:IL => "Israel",
:IM => "Isla de Man",
:IN => "India",
:IO => "Territorio Británico del Océano Índico",
:IQ => "Iraq",
:IR => "Irán",
:IS => "Islandia",
:IT => "Italia",
:JE => "Jersey",
:JM => "Jamaica",
:JO => "Jordania",
:JP => "Japón",
:KE => "Kenia",
:KG => "Kirguistán",
:KH => "Camboya",
:KI => "Kiribati",
:KM => "Comoras",
:KN => "San Cristóbal y Nieves",
:KP => "Corea del Norte",
:KR => "Corea del Sur",
:KW => "Kuwait",
:KY => "Islas Caimán",
:KZ => "Kazajistán",
:LA => "Laos",
:LB => "Líbano",
:LC => "Santa Lucía",
:LI => "Liechtenstein",
:LK => "Sri Lanka",
:LR => "Liberia",
:LS => "Lesoto",
:LT => "Lituania",
:LU => "Luxemburgo",
:LV => "Letonia",
:LY => "Libia",
:MA => "Marruecos",
:MC => "Mónaco",
:MD => "Moldavia",
:ME => "Montenegro",
:MF => "San Martín",
:MG => "Madagascar",
:MH => "Islas Marshall",
:MK => "Macedonia",
:ML => "Mali",
:MM => "Myanmar [Birmania]",
:MN => "Mongolia",
:MO => "Región Administrativa Especial de Macao de la República Popular China",
:MP => "Islas Marianas del Norte",
:MQ => "Martinica",
:MR => "Mauritania",
:MS => "Montserrat",
:MT => "Malta",
:MU => "Mauricio",
:MV => "Maldivas",
:MW => "Malaui",
:MX => "México",
:MY => "Malasia",
:MZ => "Mozambique",
:NA => "Namibia",
:NC => "Nueva Caledonia",
:NE => "Níger",
:NF => "Isla Norfolk",
:NG => "Nigeria",
:NI => "Nicaragua",
:NL => "Países Bajos",
:NO => "Noruega",
:NP => "Nepal",
:NR => "Nauru",
:NU => "Isla Niue",
:NZ => "Nueva Zelanda",
:OM => "Omán",
:PA => "Panamá",
:PE => "Perú",
:PF => "Polinesia Francesa",
:PG => "Papúa Nueva Guinea",
:PH => "Filipinas",
:PK => "Pakistán",
:PL => "Polonia",
:PM => "San Pedro y Miquelón",
:PN => "Islas Pitcairn",
:PR => "Puerto Rico",
:PS => "Territorios Palestinos",
:PT => "Portugal",
:PW => "Palau",
:PY => "Paraguay",
:QA => "Qatar",
:QO => "Territorios alejados de Oceanía",
:RE => "Reunión",
:RO => "Rumanía",
:RS => "Serbia",
:RU => "Rusia",
:RW => "Ruanda",
:SA => "Arabia Saudí",
:SB => "Islas Salomón",
:SC => "Seychelles",
:SD => "Sudán",
:SE => "Suecia",
:SG => "Singapur",
:SH => "Santa Elena",
:SI => "Eslovenia",
:SJ => "Svalbard y Jan Mayen",
:SK => "Eslovaquia",
:SL => "Sierra Leona",
:SM => "San Marino",
:SN => "Senegal",
:SO => "Somalia",
:SR => "Surinam",
:SS => "SS",
:ST => "Santo Tomé y Príncipe",
:SV => "El Salvador",
:SX => "Sint Maarten",
:SY => "Siria",
:SZ => "Suazilandia",
:TA => "Tristán da Cunha",
:TC => "Islas Turcas y Caicos",
:TD => "Chad",
:TF => "Territorios Australes Franceses",
:TG => "Togo",
:TH => "Tailandia",
:TJ => "Tayikistán",
:TK => "Tokelau",
:TL => "Timor Oriental",
:TM => "Turkmenistán",
:TN => "Túnez",
:TO => "Tonga",
:TR => "Turquía",
:TT => "Trinidad y Tobago",
:TV => "Tuvalu",
:TW => "Taiwán",
:TZ => "Tanzania",
:UA => "Ucrania",
:UG => "Uganda",
:UM => "Islas menores alejadas de los Estados Unidos",
:US => "Estados Unidos",
:UY => "Uruguay",
:UZ => "Uzbekistán",
:VA => "Ciudad del Vaticano",
:VC => "San Vicente y las Granadinas",
:VE => "Venezuela",
:VG => "Islas Vírgenes Británicas",
:VI => "Islas Vírgenes de los Estados Unidos",
:VN => "Vietnam",
:VU => "Vanuatu",
:WF => "Wallis y Futuna",
:WS => "Samoa",
:YE => "Yemen",
:YT => "Mayotte",
:ZA => "Sudáfrica",
:ZM => "Zambia",
:ZW => "Zimbabue",
:ZZ => "Región desconocida"
}
}
}
You cite your error with translation missing: es-PE.countries.
The file is named localized_country_select.es_PE.rb
The underscorse/hyphens might be cause of the problem ... or might be just a typo.

FactoryGirl3, can't access factories anymore

After I upgraded to the new FactoryGirl, I updated the syntax of the factories I inherited. Now, I bounce between either my factory isn't defined, or it's double defined. All of the answers I have found online are using older versions/syntax, and none of the proposed solutions really allows me to call my factories. I apologize for the file lengths, and I really appreciate your time! This is what I have now after having wrestled with it for a while:
spec_helper.rb
# This file is copied to spec/ when you run 'rails generate rspec:install'
ENV["RAILS_ENV"] ||= 'test'
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
require 'factory_girl'
# Requires supporting ruby files with custom matchers and macros, etc,
# in spec/support/ and its subdirectories.
Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
RSpec.configure do |config|
# ## Mock Framework
#
# If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
#
# config.mock_with :mocha
# config.mock_with :flexmock
# config.mock_with :rr
# config.mock_with :rspec
config.include FactoryGirl::Syntax::Methods
# Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
config.fixture_path = "#{::Rails.root}/spec/fixtures"
# If you're not using ActiveRecord, or you'd prefer not to run each of your
# examples within a transaction, remove the following line or assign false
# instead of true.
config.use_transactional_fixtures = true
def test_sign_in(user)
sign_in (user)
end
# If true, the base class of anonymous controllers will be inferred
# automatically. This will be the default behavior in future versions of
# rspec-rails.
config.infer_base_class_for_anonymous_controllers = false
end
factories.rb
FactoryGirl.define do
# Sequences
sequence :test_name do |n|
"Test Name #{n}"
end
sequence :email do |n|
"devnull#{n}#topsailtech.com"
end
sequence :block_offset do |n|
n*100
end
sequence :venue_position do |n|
n
end
sequence :sponsorship_position do |n|
n
end
sequence :sponsor_position do |n|
n
end
sequence :id do |n|
n
end
# factories
factory :account, :class => Account do
id { FactoryGirl.generate(:id) }
end
factory :invalid_account, :class => Account do
id ''
end
factory :activity, :class => Activity do
event { Conference.find_by_name('TechConf') }
location { |a| a.event.areas.first }
start_time { FactoryGirl.generate(:block_offset) }
end_time { FactoryGirl.generate(:block_offset) }
title { FactoryGirl.generate(:test_name) }
end
factory :invalid_activity, :class => Activity do
title ''
start_time ''
event ''
end
factory :administrator, :class => Administrator do |f|
f.email { FactoryGirl.generate(:email) }
f.first_name { FactoryGirl.generate(:test_name) }
f.last_name { FactoryGirl.generate(:test_name) }
f.password 'aBc123xYz!'
f.password_confirmation 'aBc123xYz!'
end
factory :invalid_administrator, :class => Administrator do |f|
f.email ''
f.first_name ''
f.last_name ''
f.password 'x'
f.password_confirmation 'y'
end
factory :area, :class => Area do |f|
f.event_id { Festival.find_by_name('MusicFest').id }
f.name { FactoryGirl.generate(:test_name) }
end
factory :invalid_area, :class => Area do |f|
f.name ''
f.event ''
end
factory :artist, :class => Artist do |f|
f.event_id { Festival.find_by_name('MusicFest').id }
f.name { FactoryGirl.generate(:test_name) }
f.bio 'This artist is really creative.'
f.website 'www.topsailtech.com'
end
factory :invalid_artist, :class => Artist do |f|
f.name ''
end
factory :booth, :class => Booth do |f|
f.event_id { Festival.find_by_name('MusicFest').id }
f.name { FactoryGirl.generate(:test_name) }
end
factory :invalid_booth, :class => Booth do |f|
f.name ''
end
factory :category, :class => Category do |f|
f.name { FactoryGirl.generate(:test_name) }
f.event { Festival.find_by_name('MusicFest') }
f.parent { |attrs| attrs.event.categories.first }
f.key { |a| a.name.parameterize('') }
end
factory :invalid_category, :class => Category do |f|
f.name ''
f.event ''
end
factory :top_level_category, :class => Category do |f|
f.name { FactoryGirl.generate(:test_name) }
f.event { Festival.find_by_name('MusicFest') }
f.key { |a| a.name.parameterize('') }
end
factory :conference_session_speaker, :class => ConferenceSessionSpeaker do |f|
f.conference_session { ConferenceSession.find_by_title('Giggler') }
f.speaker { |a| a.conference_session.event.speakers.first }
end
factory :invalid_conference_session_speaker, :class => ConferenceSessionSpeaker do |f|
end
factory :conference_session_without_speaker, :class => ConferenceSession do |f|
f.event { Conference.find_by_name('TechConf') }
f.location { |a| a.event.venues.first }
f.block_date { |a| a.event.start_date }
f.start_time { FactoryGirl.generate(:block_offset) }
f.end_time { FactoryGirl.generate(:block_offset) }
f.title 'Test Title'
f.subtitle 'Test Sub-title'
f.abstract 'Test abstract blah blah blah'
f.track { |a| a.event.tracks.first }
end
factory :conference_session, :class => ConferenceSession, :parent => :conference_session_without_speaker do |f|
f.speaker { |a| a.event.speakers.first }
end
factory :invalid_conference_session, :class => ConferenceSession do |f|
f.event nil
f.title ''
end
factory :conference, :class => Conference do |f|
f.account_id { Factory.create(:account).id }
f.name { FactoryGirl.generate(:test_name) }
f.start_date { Date.today + 1 }
f.end_date { Date.today + 3 }
f.copyright 'Giggler, Inc.'
end
factory :invalid_conference, :class => Conference do |f|
f.name ''
end
factory :festival, :class => Festival do |f|
f.account_id { Factory.create(:account).id }
f.name { FactoryGirl.generate(:test_name) }
f.start_date { Date.today + 1 }
f.end_date { Date.today + 3 }
f.copyright 'Giggler, Inc.'
end
factory :invalid_festival, :class => Festival do |f|
f.name ''
end
factory :performance, :class => Performance do |f|
f.event { Festival.find_by_name('MusicFest') }
f.location { |a| a.event.venues.first }
f.contributor { |a| a.event.artists.first }
f.block_date { |a| a.event.start_date }
f.start_time { FactoryGirl.generate(:block_offset) }
f.end_time { FactoryGirl.generate(:block_offset) }
end
factory :invalid_performance, :class => Performance do |f|
end
factory :series, :class => Series do |f|
f.event { Conference.find_by_name('TechConf') }
f.location { |a| a.event.venues.first }
f.block_date { |a| a.event.start_date }
f.start_time { FactoryGirl.generate(:block_offset) }
f.end_time { FactoryGirl.generate(:block_offset) }
f.title 'Test Title'
f.subtitle 'Test Sub-title'
f.abstract 'Test abstract blah blah blah'
f.track { |a| a.event.tracks.first }
end
factory :invalid_series, :class => Series do |f|
f.title ''
end
factory :speaker, :class => Speaker do |f|
f.event { Conference.find_by_name('TechConf') }
f.first_name 'John'
f.last_name 'Doe'
f.credentials 'Dr.'
f.organization 'TechCom'
f.title 'Director'
f.website 'blahblahblahblahblah.com'
f.street_address '123 Foo Road'
f.city 'Townsville'
f.state 'NC'
f.zip_code '27519'
f.bio 'Blah blah blah blah blah'
end
factory :invalid_speaker, :class => Speaker do |f|
end
factory :sponsor, :class => Sponsor do |f|
f.name { FactoryGirl.generate(:test_name) }
f.show_logo true
f.website 'topsailtech.com'
f.sponsorship { Factory.create(:sponsorship) }
end
factory :invalid_sponsor, :class => Sponsor do |f|
f.name ''
end
factory :sponsorship, :class => Sponsorship do |f|
f.name { FactoryGirl.generate(:test_name) }
f.position { FactoryGirl.generate(:sponsorship_position) }
f.show_logo true
f.event { Conference.find_by_name('TechConf') }
end
factory :invalid_sponsorship, :class => Sponsorship do |f|
f.name ''
f.position ''
f.show_logo ''
f.event ''
end
factory :track, :class => Track do |f|
f.event { Conference.find_by_name('TechConf') }
f.name { FactoryGirl.generate(:test_name) }
end
factory :invalid_track, :class => Track do |f|
f.event ''
f.name ''
end
factory :vendor, :class => Vendor do
association event :factory => :festival, :name => 'MusicFest'
category { |a| a.event.categories.first }
location { |a| a.event.venues.first }
name { FactoryGirl.generate(:test_name) }
bio 'They sell things.'
website 'www.topsailtech.com'
end
factory :invalid_vendor, :class => Vendor do |f|
f.name ''
end
factory :venue, :class => Venue do
event { Festival.find_by_name('MusicFest') }
name test_name
street_address '406 Blackwell St.'
city 'Durham'
state 'NC'
zip_code '27701'
position venue_position
key { |a| a.name.parameterize('') }
end
factory :invalid_venue, :class => Venue do |f|
f.name ''
end
end
controller/this_controller_spec.rb
require 'spec_helper'
describe GigViewController do
include Devise::TestHelpers
fixtures :all
render_views
describe "GET all GigViews" do
before(:each) do
#user = user_profile(:doc)
#event = event(:merlefest)
end
it "should be successful" do
test_sign_in #user
get :show, :id => #event.id
response.should be_success
end
**... removed multiple other tests that work but don't use fixtures ...**
it "should get music" do
sign_in #user
venue = FactoryGirl.create(:venue)
get :music, :id => #event.id
response.should be_success
end
end
end
Gemfile.lock (excerpt)
factory_girl (3.0.0)
activesupport (>= 3.0.0)
factory_girl_rails (3.0.0)
factory_girl (~> 3.0.0)
railties (>= 3.0.0)
rails (3.1.3)
actionmailer (= 3.1.3)
actionpack (= 3.1.3)
activerecord (= 3.1.3)
activeresource (= 3.1.3)
activesupport (= 3.1.3)
bundler (~> 1.0)
railties (= 3.1.3)
rspec-rails (2.9.0)
actionpack (>= 3.0)
activesupport (>= 3.0)
railties (>= 3.0)
rspec (~> 2.9.0)
I started over, and this is what I've got so far. It works now, and I hope that posting this will help someone trying to get things started, as I was:
spec_helper.rb
# This file is copied to spec/ when you run 'rails generate rspec:install'
ENV["RAILS_ENV"] ||= 'test'
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
require 'rspec/autorun'
require 'factory_girl_rails'
# Requires supporting ruby files with custom matchers and macros, etc,
# in spec/support/ and its subdirectories.
Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
RSpec.configure do |config|
config.include Devise::TestHelpers, :type => :controller
# ## Mock Framework
#
# If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
#
# config.mock_with :mocha
# config.mock_with :flexmock
# config.mock_with :rr
# Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
config.fixture_path = "#{::Rails.root}/spec/fixtures"
# If you're not using ActiveRecord, or you'd prefer not to run each of your
# examples within a transaction, remove the following line or assign false
# instead of true.
config.use_transactional_fixtures = true
# If true, the base class of anonymous controllers will be inferred
# automatically. This will be the default behavior in future versions of
# rspec-rails.
config.infer_base_class_for_anonymous_controllers = false
# Use color in STDOUT
config.color_enabled = true
# Use color not only in STDOUT but also in pagers and files
config.tty = true
# Use the specified formatter
config.formatter = :documentation # :progress, :html, :textmate
end
factories.rb
FactoryGirl.define do
factory :user_profile, :class => UserProfile do
first_name 'John'
last_name 'Doe'
email { "#{first_name}.#{last_name}#example.com".downcase }
username 'johndoe'
password 'johndoe'
password_confirmation 'johndoe'
association :account, :factory => :account
end
factory :account, :class => Account do
# id { FactoryGirl.generate(:id) }
end
factory :event, :class => Event do
name 'Shakori'
association :account, :factory => :account
end
end
controllers/account_controller.rb
require 'spec_helper'
describe AccountController do
render_views
describe "do not GET 'event" do
before(:each) do
#request.env["devise.mapping"] = Devise.mappings[:user_profile]
end
it "should fail when user is not logged in" do
get :events
response.should_not be_success
end
end
describe "GET 'event'" do
before(:each) do
#request.env["devise.mapping"] = Devise.mappings[:user_profile]
sign_in FactoryGirl.create(:user_profile, :username => 'johndoe' )
end
it "should be successful, if logged in" do
get :events
response.should be_success
end
end
end

Resources