Validate application settings only if column exists

This commit is contained in:
Dmitriy Zaporozhets 2015-01-16 17:22:17 -08:00
parent e7f772550c
commit 38600e328b
2 changed files with 7 additions and 2 deletions

View File

@ -1,6 +1,7 @@
class ApplicationSetting < ActiveRecord::Base
validates :home_page_url, allow_blank: true,
format: { with: URI::regexp(%w(http https)), message: "should be a valid url" }
format: { with: URI::regexp(%w(http https)), message: "should be a valid url" },
if: :home_page_url_column_exist
def self.current
ApplicationSetting.last
@ -15,4 +16,8 @@ class ApplicationSetting < ActiveRecord::Base
sign_in_text: Settings.extra['sign_in_text'],
)
end
def home_page_url_column_exist
ActiveRecord::Base.connection.column_exists?(:application_settings, :home_page_url)
end
end

View File

@ -424,7 +424,6 @@ ActiveRecord::Schema.define(version: 20150116234544) do
t.integer "notification_level", default: 1, null: false
t.datetime "password_expires_at"
t.integer "created_by_id"
t.datetime "last_credential_check_at"
t.string "avatar"
t.string "confirmation_token"
t.datetime "confirmed_at"
@ -432,6 +431,7 @@ ActiveRecord::Schema.define(version: 20150116234544) do
t.string "unconfirmed_email"
t.boolean "hide_no_ssh_key", default: false
t.string "website_url", default: "", null: false
t.datetime "last_credential_check_at"
t.string "github_access_token"
end