diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index e6f4959..048b410 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -77,4 +77,14 @@ class ApplicationController < ActionController::Base end end + def profile_path(user) + if user.username + public_profile_path(username: user.username) + else + unnamed_user_path(user) + end + end + + helper_method :profile_path + end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 174dbbd..80bf34d 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -9,7 +9,12 @@ class UsersController < ApplicationController end def show - user = User.for_username!(params[:username]) + if params[:username] + user = User.for_username!(params[:username]) + else + user = User.find(params[:id]) + end + render locals: { page: UserPagePresenter.build(user, current_user, params[:page]) } end diff --git a/app/decorators/user_decorator.rb b/app/decorators/user_decorator.rb index 4dc6c4b..787acee 100644 --- a/app/decorators/user_decorator.rb +++ b/app/decorators/user_decorator.rb @@ -2,7 +2,7 @@ class UserDecorator < ApplicationDecorator include AvatarHelper def link - wrap_with_link(username || temporary_username || 'anonymous') + wrap_with_link(username || temporary_username || "user:#{id}") end def img_link @@ -28,8 +28,9 @@ class UserDecorator < ApplicationDecorator private def wrap_with_link(html) - if username - h.link_to html, h.profile_path(model), title: username + if id + title = username || temporary_username || 'anonymous user' + h.link_to html, h.profile_path(model), title: title else html end diff --git a/app/models/user.rb b/app/models/user.rb index 05cfd37..6abb259 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -81,10 +81,6 @@ class User < ActiveRecord::Base theme_name.presence && Theme.for_name(theme_name) end - def to_param - username - end - def assign_api_token(token) api_token = ApiToken.for_token(token) diff --git a/config/routes.rb b/config/routes.rb index 62a141e..d74118f 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -12,7 +12,8 @@ Rails.application.routes.draw do end end - get "/~:username" => "users#show", :as => :profile + get "/u/:id" => "users#show", as: :unnamed_user + get "/~:username" => "users#show", as: :public_profile namespace :api do resources :asciicasts