Permalink
Browse files

Adds twitter format validation

Fixes rendering of twitter
  • Loading branch information...
1 parent 1d7c594 commit 4dcb734617d4549f3c9a1a05dc19d6be77a3828f @elight elight committed Aug 20, 2011
Showing with 10 additions and 5 deletions.
  1. +6 −3 app/controllers/users_controller.rb
  2. +2 −0 app/models/user.rb
  3. +1 −1 app/views/users/_user.html.haml
  4. +1 −1 app/views/users/show.html.haml
@@ -9,9 +9,12 @@ def edit
end
def update
- current_user.update_attributes(params[:user])
- flash[:notice] = "Your profile has been updated!"
- redirect_to :root
+ if current_user.update_attributes(params[:user])
+ flash[:notice] = "Your profile has been updated!"
+ redirect_to :root
+ else
+ render :edit
+ end
end
private
View
@@ -17,5 +17,7 @@ class User
REMOTE_LOCAL_PREFERENCES = ["Local", "Remote", "Both"]
fulltext_search_in :name, :github_login, :interests
+
+ validates_format_of :twitter, with: /^\w+$/, message: "if present must not start with a '@'"
end
@@ -4,4 +4,4 @@
%h4.user-name= user.name
%h4.github-login= link_to user.github_login, "http://github.com/#{user.github_login}"
- if user.twitter
- %h4.twitter-handle= link_to user.twitter, "http://twitter.com/#{user.twitter[1..-1]}"
+ %h4.twitter-handle= link_to "@#{user.twitter}", "http://twitter.com/#{user.twitter}"
@@ -13,7 +13,7 @@
- if @user.twitter.present?
%li.twitter
%label Twitter
- = link_to @user.twitter, "http://twitter.com/#{@user.twitter[1..-1]}"
+ = link_to "@#{user.twitter}", "http://twitter.com/#{@user.twitter}"
%li.pairing-preference
%label
Pairing preference

0 comments on commit 4dcb734

Please sign in to comment.