From 8f8ad571353300e6bf66f320591129657981fc32 Mon Sep 17 00:00:00 2001 From: joshua stein Date: Thu, 9 Apr 2015 21:05:50 -0500 Subject: [PATCH] export a json version of user page, include karma and about text --- app/controllers/users_controller.rb | 5 +++++ app/models/user.rb | 2 ++ config/routes.rb | 2 +- 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 98dce5c..eeb4ba6 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -2,6 +2,11 @@ class UsersController < ApplicationController def show @showing_user = User.where(:username => params[:username]).first! @title = "User #{@showing_user.username}" + + respond_to do |format| + format.html { render :action => "show" } + format.json { render :json => @showing_user } + end end def tree diff --git a/app/models/user.rb b/app/models/user.rb index f9282b6..cb15023 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -78,6 +78,8 @@ class User < ActiveRecord::Base :created_at, :is_admin, :is_moderator, + :karma, + :about, ]) h[:avatar_url] = avatar_url h diff --git a/config/routes.rb b/config/routes.rb index 5cd3496..aa5b744 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -87,7 +87,7 @@ Lobsters::Application.routes.draw do get "/c/:id" => "comments#redirect_from_short_id" get "/u" => "users#tree" - get "/u/:username" => "users#show", :as => "user" + get "/u/:username" => "users#show", :as => "user", :format => /html|json/ get "/settings" => "settings#index" post "/settings" => "settings#update"