From c399ddf18d7afcd80411d50048a67e135b02bead Mon Sep 17 00:00:00 2001 From: kikito Date: Fri, 11 Sep 2015 11:32:29 +0200 Subject: [PATCH] Adds default values to limits when the db does not have them This prevents errors when doing rake db:setup (the db has still not been created but the rails models are loaded) --- app/models/debate.rb | 2 +- app/models/organization.rb | 2 +- app/models/user.rb | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/models/debate.rb b/app/models/debate.rb index 968431324..c30bc7b8d 100644 --- a/app/models/debate.rb +++ b/app/models/debate.rb @@ -147,7 +147,7 @@ class Debate < ActiveRecord::Base end def self.title_max_length - @@title_max_length ||= self.columns.find { |c| c.name == 'title' }.limit + @@title_max_length ||= self.columns.find { |c| c.name == 'title' }.limit || 80 end def self.description_max_length diff --git a/app/models/organization.rb b/app/models/organization.rb index fc9b8cec1..0797849e7 100644 --- a/app/models/organization.rb +++ b/app/models/organization.rb @@ -34,7 +34,7 @@ class Organization < ActiveRecord::Base end def self.name_max_length - @@name_max_length ||= self.columns.find { |c| c.name == 'name' }.limit + @@name_max_length ||= self.columns.find { |c| c.name == 'name' }.limit || 60 end private diff --git a/app/models/user.rb b/app/models/user.rb index 08dfd6609..3ddf4df54 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -144,7 +144,7 @@ class User < ActiveRecord::Base end def self.username_max_length - @@username_max_length ||= self.columns.find { |c| c.name == 'username' }.limit + @@username_max_length ||= self.columns.find { |c| c.name == 'username' }.limit || 60 end def show_welcome_screen?