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
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
# update the entire set of preferences
def update
begin
- p = XML::Parser.new
- p.string = request.raw_post
+ p = XML::Parser.string(request.raw_post)
doc = p.parse
prefs = []
render :nothing => true
end
-
end