X-Git-Url: https://git.openstreetmap.org./rails.git/blobdiff_plain/4b3c207a818b936310f48b768488a6a39845fe81..a21824f754ddea0e45beb87cdaa371e74359e2e2:/app/controllers/user_preference_controller.rb diff --git a/app/controllers/user_preference_controller.rb b/app/controllers/user_preference_controller.rb index a4de5c099..559479929 100644 --- a/app/controllers/user_preference_controller.rb +++ b/app/controllers/user_preference_controller.rb @@ -3,7 +3,7 @@ class UserPreferenceController < ApplicationController before_filter :authorize def read_one - pref = UserPreference.find(:first, :conditions => ['user_id = ? AND k = ?', @user.id, params[:preference_key]]) + pref = UserPreference.find(@user.id, params[:preference_key]) if pref render :text => pref.v.to_s @@ -13,20 +13,26 @@ class UserPreferenceController < ApplicationController end def update_one - pref = UserPreference.find(:first, :conditions => ['user_id = ? AND k = ?', @user.id, params[:preference_key]]) - - if pref + begin + pref = UserPreference.find(@user.id, params[:preference_key]) pref.v = request.raw_post.chomp pref.save - else + rescue ActiveRecord::RecordNotFound pref = UserPreference.new pref.user = @user pref.k = params[:preference_key] pref.v = request.raw_post.chomp pref.save end + + render :nothing => true end + def delete_one + UserPreference.delete(@user.id, params[:preference_key]) + + render :nothing => true + end # print out all the preferences as a big xml block def read @@ -91,5 +97,4 @@ class UserPreferenceController < ApplicationController render :nothing => true end - end