Skip to content

Instantly share code, notes, and snippets.

@soulfly
Created March 25, 2013 07:05
Show Gist options
  • Save soulfly/5235390 to your computer and use it in GitHub Desktop.
Save soulfly/5235390 to your computer and use it in GitHub Desktop.
def update_record
json_data = JSON.parse(params["record"]["json_body"])
data = CustomData.where(:id => params["record"]["id"], :application_id => @current_app.id).first
authorize! :update, data
data.update_attributes typify_hash(json_data)
if json_data["user_id"] != data.user_id
begin
user = User.find(json_data["user_id"].to_i)
data.user_id = user.id if (user.account_id == @current_user.account_id)
rescue
end
end
if data.save
render :json => {:success => true}
else
render :json => {:success => false, :message => data.errors.full_messages.first}
end
rescue JSON::ParserError
render :json => {:success => false, :message => "Parse error"}
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment