end
def make_friend
- if params[:display_name]
- name = params[:display_name]
- new_friend = User.active.where(:display_name => name).first
- friend = Friend.new
- friend.user_id = @user.id
- friend.friend_user_id = new_friend.id
- unless @user.is_friends_with?(new_friend)
- if friend.save
- flash[:notice] = t 'user.make_friend.success', :name => name
- Notifier.friend_notification(friend).deliver
+ @new_friend = User.find_by_display_name(params[:display_name])
+
+ if @new_friend
+ if request.post?
+ friend = Friend.new
+ friend.user_id = @user.id
+ friend.friend_user_id = @new_friend.id
+ unless @user.is_friends_with?(@new_friend)
+ if friend.save
+ flash[:notice] = t 'user.make_friend.success', :name => @new_friend.display_name
+ Notifier.friend_notification(friend).deliver
+ else
+ friend.add_error(t('user.make_friend.failed', :name => @new_friend.display_name))
+ end
else
- friend.add_error(t('user.make_friend.failed', :name => name))
+ flash[:warning] = t 'user.make_friend.already_a_friend', :name => @new_friend.display_name
end
- else
- flash[:warning] = t 'user.make_friend.already_a_friend', :name => name
- end
- if params[:referer]
- redirect_to params[:referer]
- else
- redirect_to :controller => 'user', :action => 'view'
+ if params[:referer]
+ redirect_to params[:referer]
+ else
+ redirect_to :controller => 'user', :action => 'view'
+ end
end
+ else
+ render_unknown_user params[:display_name]
end
end
def remove_friend
- if params[:display_name]
- name = params[:display_name]
- friend = User.active.where(:display_name => name).first
- if @user.is_friends_with?(friend)
- Friend.delete_all "user_id = #{@user.id} AND friend_user_id = #{friend.id}"
- flash[:notice] = t 'user.remove_friend.success', :name => friend.display_name
- else
- flash[:error] = t 'user.remove_friend.not_a_friend', :name => friend.display_name
- end
+ @friend = User.find_by_display_name(params[:display_name])
- if params[:referer]
- redirect_to params[:referer]
- else
- redirect_to :controller => 'user', :action => 'view'
+ if @friend
+ if request.post?
+ if @user.is_friends_with?(@friend)
+ Friend.delete_all "user_id = #{@user.id} AND friend_user_id = #{@friend.id}"
+ flash[:notice] = t 'user.remove_friend.success', :name => @friend.display_name
+ else
+ flash[:error] = t 'user.remove_friend.not_a_friend', :name => @friend.display_name
+ end
+
+ if params[:referer]
+ redirect_to params[:referer]
+ else
+ redirect_to :controller => 'user', :action => 'view'
+ end
end
+ else
+ render_unknown_user params[:display_name]
end
end
<%= link_to t('user.view.send message'), :controller => 'message', :action => 'new', :display_name => contact.display_name %>
|
<% if @user.is_friends_with?(contact) %>
- <%= link_to t('user.view.remove as friend'), :controller => 'user', :action => 'remove_friend', :display_name => contact.display_name, :referer => request.fullpath, :method => :post %>
+ <%= link_to t('user.view.remove as friend'), remove_friend_path(:display_name => contact.display_name, :referer => request.fullpath), :method => :post %>
<% else %>
- <%= link_to t('user.view.add as friend'), :controller => 'user', :action => 'make_friend', :display_name => contact.display_name, :referer => request.fullpath, :method => :post %>
+ <%= link_to t('user.view.add as friend'), make_friend_path(:display_name => contact.display_name, :referer => request.fullpath), :method => :post %>
<% end %>
</td>
</tr>
--- /dev/null
+<h1><%= t "user.make_friend.heading", :user => @new_friend.display_name %></h1>
+<%= form_tag do %>
+ <% if params[:referer] -%>
+ <%= hidden_field_tag("referer", params[:referer]) %>
+ <% end -%>
+ <%= submit_tag t("user.make_friend.button") %>
+<% end %>
--- /dev/null
+<h1><%= t "user.remove_friend.heading", :user => @friend.display_name %></h1>
+<%= form_tag do %>
+ <% if params[:referer] -%>
+ <%= hidden_field_tag("referer", params[:referer]) %>
+ <% end -%>
+ <%= submit_tag t("user.remove_friend.button") %>
+<% end %>
<%= link_to t('user.view.comments'), :controller => 'diary_entry', :action => 'comments', :display_name => @this_user.display_name %>
|
<% if @user and @user.is_friends_with?(@this_user) %>
- <%= link_to t('user.view.remove as friend'), :controller => 'user', :action => 'remove_friend', :display_name => @this_user.display_name, :method => :post %>
+ <%= link_to t('user.view.remove as friend'), remove_friend_path(:display_name => @this_user.display_name), :method => :post %>
<% else %>
- <%= link_to t('user.view.add as friend'), :controller => 'user', :action => 'make_friend', :display_name => @this_user.display_name, :method => :post %>
+ <%= link_to t('user.view.add as friend'), make_friend_path(:display_name => @this_user.display_name), :method => :post %>
<% end %>
<% if @this_user.blocks.exists? %>
|
go_public:
flash success: "All your edits are now public, and you are now allowed to edit."
make_friend:
+ heading: "Add %{user} as a friend?"
+ button: "Add as friend"
success: "%{name} is now your friend."
failed: "Sorry, failed to add %{name} as a friend."
already_a_friend: "You are already friends with %{name}."
remove_friend:
+ heading: "Remove %{user} as a friend?"
+ button: "Remove as friend"
success: "%{name} was removed from your friends."
not_a_friend: "%{name} is not one of your friends."
filter:
# user pages
match '/user/:display_name' => 'user#view', :via => :get, :as => "user"
- match '/user/:display_name/make_friend' => 'user#make_friend', :via => :post
- match '/user/:display_name/remove_friend' => 'user#remove_friend', :via => :post
+ match '/user/:display_name/make_friend' => 'user#make_friend', :via => [:get, :post], :as => "make_friend"
+ match '/user/:display_name/remove_friend' => 'user#remove_friend', :via => [:get, :post], :as => "remove_friend"
match '/user/:display_name/account' => 'user#account', :via => [:get, :post]
match '/user/:display_name/set_status' => 'user#set_status', :via => :get, :as => :set_status_user
match '/user/:display_name/delete' => 'user#delete', :via => :get, :as => :delete_user
{ :controller => "user", :action => "account", :display_name => "username" }
)
+ assert_routing(
+ { :path => "/user/username/make_friend", :method => :get },
+ { :controller => "user", :action => "make_friend", :display_name => "username" }
+ )
assert_routing(
{ :path => "/user/username/make_friend", :method => :post },
{ :controller => "user", :action => "make_friend", :display_name => "username" }
)
+ assert_routing(
+ { :path => "/user/username/remove_friend", :method => :get },
+ { :controller => "user", :action => "remove_friend", :display_name => "username" }
+ )
assert_routing(
{ :path => "/user/username/remove_friend", :method => :post },
{ :controller => "user", :action => "remove_friend", :display_name => "username" }