Browse files

fix properly displaying user's profile, and comment data

  • Loading branch information...
1 parent 2a132e5 commit bbcbcebf035627e9c7e1817c938bb4dacec9949f @ck3g committed Mar 30, 2013
View
7 app/controllers/profiles_controller.rb
@@ -27,6 +27,11 @@ def sync
private
def find_profile
- @profile = Profile.find params[:id]
+ if params[:username].present?
+ profile_id = User.where(username: params[:username]).first.try(:profile).try(:id)
+ @profile = Profile.find profile_id
+ else
+ @profile = Profile.find params[:id]
+ end
end
end
View
4 app/helpers/application_helper.rb
@@ -15,10 +15,6 @@ def twitterized_type(type)
end
end
- def avatar_tag(user)
- image_tag "avatars/default.gif"
- end
-
def link_to_nav(title, path)
content_tag :li, :class => ("active" if current_page?(path)) do
link_to title, path
View
16 app/helpers/comments_helper.rb
@@ -1,2 +1,18 @@
module CommentsHelper
+ def avatar_tag(user)
+ if user
+ avatar_html user.profile
+ else
+ image_tag "avatars/default.gif"
+ end
+ end
+
+ def link_to_commenter(comment)
+ if comment.user
+ link_to comment.username, user_profile_path(comment.username)
+ else
+ "#{t(:unknown_user)}"
+ end
+ end
+
end
View
2 app/models/comment.rb
@@ -6,7 +6,7 @@ class Comment < ActiveRecord::Base
belongs_to :user
belongs_to :commentable, :polymorphic => true
- validates :comment, :user_id, presence: true
+ validates :comment, presence: true
default_scope :order => 'created_at ASC'
View
2 app/views/articles/_article.html.haml
@@ -18,7 +18,7 @@
.pull-right
= succeed ":" do
= t(:published_by)
- = link_to profile_path(article.user.profile) do
+ = link_to user_profile_path(article.user.username) do
= article.user_name || article.user_email
= " @"
= l article.published_at, format: :long
View
2 app/views/comments/_comment.html.haml
@@ -2,7 +2,7 @@
.span12.well.js-comment-content
.span2
%p= avatar_tag(comment.user)
- %p= link_to comment.username, "#"
+ %p= link_to_commenter comment
.span10.clearfix
- if can? :manage, comment
.manage-button-wrapper
View
3 app/views/profiles/show.html.haml
@@ -15,7 +15,8 @@
= profile_attribute_block Profile.human_attribute_name(:fullname), @profile.fullname
= profile_attribute_block Profile.human_attribute_name(:country), @profile.country_name
= profile_attribute_block Profile.human_attribute_name(:created_at), l(@profile.created_at, format: :long)
- = profile_attribute_block Profile.human_attribute_name(:user_current_sign_in_at), l(@profile.user_current_sign_in_at, format: :long)
+ - current_sign_in_at = l(@profile.user_current_sign_in_at, format: :long) if @profile.user_current_sign_in_at.present?
+ = profile_attribute_block Profile.human_attribute_name(:user_current_sign_in_at), current_sign_in_at
- if @profile.profile_url?
.row-fluid
View
2 app/views/shared/_top_nav_bar.html.haml
@@ -24,7 +24,7 @@
= current_user.name
%span.caret
%ul.dropdown-menu
- %li= link_to t("users.profile"), profile_path(current_user)
+ %li= link_to t("users.profile"), user_profile_path(current_user.username)
%li= link_to t("users.account"), edit_user_registration_path
- if can? :manage, User
%li.divider
View
1 config/locales/ru.yml
@@ -126,3 +126,4 @@ ru:
edit_user: "Редактировать пользователя - %{user}"
change_password: Смена пароля
change_my_password: Сменить мой пароль
+ unknown_user: Неизвестный
View
1 config/routes.rb
@@ -22,6 +22,7 @@
resources :profiles, only: [:show, :edit, :update] do
put :sync, on: :member
end
+ get "profile/:username" => "profiles#show", as: :user_profile
root :to => 'articles#index'
end
View
1 spec/models/comment_spec.rb
@@ -14,7 +14,6 @@
context "when valid" do
subject { create :comment }
it { should validate_presence_of :comment }
- it { should validate_presence_of :user_id }
end
end

0 comments on commit bbcbceb

Please sign in to comment.