resolved user.rb conflict

This commit is contained in:
Nick Black 2007-05-05 14:24:08 +00:00
parent bfdef8dc68
commit 7bcda2794f
4 changed files with 40 additions and 11 deletions

View file

@ -2,8 +2,8 @@ class UserController < ApplicationController
layout 'site'
before_filter :authorize, :only => [:preferences, :api_details, :api_gpx_files]
before_filter :authorize_web, :only => [:edit, :account, :go_public, :view, :diary]
before_filter :require_user, :only => [:edit, :set_home, :account, :go_public]
before_filter :authorize_web, :only => [:edit, :account, :go_public, :view, :diary, :make_friend]
before_filter :require_user, :only => [:edit, :set_home, :account, :go_public, :make_friend]
def save
@user = User.new(params[:user])
@ -164,7 +164,22 @@ class UserController < ApplicationController
end
def make_friend
if params[:display_name]
name = params[:display_name]
friend = Friend.new
friend.user_id = @user.id
friend.friend_user_id = User.find_by_display_name(name).id
unless @user.is_friends_with?(friend)
if friend.save
flash[:notice] = "#{name} is now your friend"
else
friend.add_error("adding a friend failed")
end
else
flash[:notice] = "Your are already friends"
end
redirect_to :controller => 'user', :action => 'view'
end
end

View file

@ -5,6 +5,7 @@ class User < ActiveRecord::Base
has_many :traces
has_many :diary_entries
has_many :messages, :foreign_key => :to_user_id
has_many :friends
validates_confirmation_of :pass_crypt, :message => 'Password must match the confirmation password'
validates_uniqueness_of :display_name, :allow_nil => true
@ -60,7 +61,6 @@ class User < ActiveRecord::Base
end
def nearby(lat_range=1, lon_range=1)
if self.home_lon and self.home_lat
nearby = User.find(:all, :conditions => "#{self.home_lon} > home_lon - #{lon_range} and #{self.home_lon} < home_lon + #{lon_range} and #{self.home_lon} > home_lon - #{lon_range} and #{self.home_lon} < home_lon + #{lon_range} and data_public = 1")
else
@ -87,5 +87,15 @@ class User < ActiveRecord::Base
return messages
end
def is_friends_with?(new_friend)
res = false
@new_friend = new_friend
self.friends.each do |friend|
if friend.user_id == @new_friend.user_id
return true
end
end
return false
end
end

View file

@ -63,6 +63,7 @@ ActionController::Routing::Routes.draw do |map|
map.connect '/traces/tag/:tag/page/:page', :controller => 'trace', :action => 'list', :id => nil
# user pages
map.connect '/user/:display_name/make_friend', :controller => 'user', :action => 'make_friend'
map.connect '/user/:display_name', :controller => 'user', :action => 'view'
map.connect '/user/:display_name/diary', :controller => 'user', :action => 'diary'
map.connect '/user/:display_name/diary/newpost', :controller => 'diary_entry', :action => 'new'

View file

@ -46,3 +46,6 @@ alter table users add column within_lon double default 2;
alter table users add column within_lat double default 2;
create table messages (id bigint not null auto_increment, user_id bigint(20) not null, from_user_id bigint(20) not null, title varchar(255), body text, sent_on datetime, message_read boolean default 0, primary key(id));
create table friends (id bigint not null auto_increment, user_id bigint(20) not null, friend_user_id(20) not null, primary key(id));
create index user_id_idx on friends(friend_user_id);