Link to anonymous users profiles

footer-fixes
Marcin Kulik 10 years ago
parent 9064a37e24
commit bf54046836

@ -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

@ -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

@ -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

@ -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)

@ -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

Loading…
Cancel
Save