only update needed columns when saving to database

This commit is contained in:
Kyle Drake 2014-09-16 00:53:57 -07:00
parent 27525c2762
commit e92f13728d

26
app.rb
View file

@ -261,9 +261,8 @@ post '/plan/create' do
email: current_site.email, email: current_site.email,
plan: params[:selected_plan] plan: params[:selected_plan]
) )
current_site.stripe_customer_id = customer.id
current_site.plan_ended = false current_site.update stripe_customer_id: customer.id, plan_ended: false
current_site.save
plan_name = customer.subscriptions.first['plan']['name'] plan_name = customer.subscriptions.first['plan']['name']
@ -319,8 +318,7 @@ post '/plan/end' do
subscriptions.each do |subscription| subscriptions.each do |subscription|
customer.subscriptions.retrieve(subscription.id).delete customer.subscriptions.retrieve(subscription.id).delete
end end
current_site.plan_ended = true current_site.update plan_ended: true
current_site.save
end end
redirect '/plan' redirect '/plan'
@ -344,7 +342,7 @@ post '/tags/add' do
current_site.new_tags_string = params[:tags] current_site.new_tags_string = params[:tags]
if current_site.valid? if current_site.valid?
current_site.save current_site.save_changes
else else
flash[:errors] = current_site.errors.first flash[:errors] = current_site.errors.first
end end
@ -650,9 +648,7 @@ post '/settings/ssl' do
end end
end end
current_site.ssl_key = key.to_pem current_site.update ssl_key: key.to_pem, ssl_cert: cert_array.join
current_site.ssl_cert = cert_array.join
current_site.save
flash[:success] = 'Updated SSL key/certificate.' flash[:success] = 'Updated SSL key/certificate.'
redirect '/custom_domain' redirect '/custom_domain'
@ -710,7 +706,7 @@ post '/change_password' do
end end
if current_site.errors.empty? if current_site.errors.empty?
current_site.save current_site.save_changes
flash[:success] = 'Successfully changed password.' flash[:success] = 'Successfully changed password.'
redirect '/settings' redirect '/settings'
else else
@ -762,7 +758,7 @@ post '/change_name' do
if current_site.valid? if current_site.valid?
DB.transaction { DB.transaction {
current_site.save current_site.save_changes
current_site.move_files_from old_username current_site.move_files_from old_username
} }
@ -1009,7 +1005,7 @@ post '/admin/mark_nsfw' do
end end
site.is_nsfw = true site.is_nsfw = true
site.save validate: false site.save_changes validate: false
flash[:success] = 'MISSION ACCOMPLISHED' flash[:success] = 'MISSION ACCOMPLISHED'
redirect '/admin' redirect '/admin'
@ -1075,7 +1071,7 @@ get '/password_reset_confirm' do
if sites.length > 0 if sites.length > 0
sites.each do |site| sites.each do |site|
site.password = reset_site.password_reset_token site.password = reset_site.password_reset_token
site.save site.save_changes
end end
flash[:success] = 'Your password for all sites with your email address has been changed to the token sent in your e-mail. Please login and change your password as soon as possible.' flash[:success] = 'Your password for all sites with your email address has been changed to the token sent in your e-mail. Please login and change your password as soon as possible.'
@ -1096,7 +1092,7 @@ post '/custom_domain' do
current_site.domain = params[:domain] current_site.domain = params[:domain]
if current_site.valid? if current_site.valid?
current_site.save current_site.save_changes
flash[:success] = 'The domain has been successfully updated.' flash[:success] = 'The domain has been successfully updated.'
redirect '/custom_domain' redirect '/custom_domain'
else else
@ -1320,7 +1316,7 @@ get '/site/:username/confirm_email/:token' do
site = Site[username: params[:username]] site = Site[username: params[:username]]
if site.email_confirmation_token == params[:token] if site.email_confirmation_token == params[:token]
site.email_confirmed = true site.email_confirmed = true
site.save site.save_changes
erb :'site_email_confirmed' erb :'site_email_confirmed'
else else