From: Steve Coast Date: Sat, 7 Apr 2007 20:12:35 +0000 (+0000) Subject: various diary bits X-Git-Tag: live~8524 X-Git-Url: https://git.openstreetmap.org/rails.git/commitdiff_plain/f498a9287a25fc284ef0e1fd90ea8ca91e661183 various diary bits --- diff --git a/app/controllers/diary_entry_controller.rb b/app/controllers/diary_entry_controller.rb index 7c77fc177..c25c8718d 100644 --- a/app/controllers/diary_entry_controller.rb +++ b/app/controllers/diary_entry_controller.rb @@ -1,2 +1,16 @@ class DiaryEntryController < ApplicationController + layout 'site' + + before_filter :authorize_web + before_filter :require_user + + def new + if params[:diary_entry] + @entry = DiaryEntry.new(@params[:diary_entry]) + @entry.user = @user + if @entry.save + redirect_to :controller => 'user', :action => 'diary', :display_name => @user.display_name + end + end + end end diff --git a/app/controllers/user_controller.rb b/app/controllers/user_controller.rb index 9fd20f2ff..3837d0976 100644 --- a/app/controllers/user_controller.rb +++ b/app/controllers/user_controller.rb @@ -2,7 +2,7 @@ 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] + before_filter :authorize_web, :only => [:edit, :account, :go_public, :view, :diary] before_filter :require_user, :only => [:edit, :account, :go_public] def save @@ -139,11 +139,14 @@ class UserController < ApplicationController render :text => doc.to_s end - def view @this_user = User.find_by_display_name(params[:display_name]) end + def diary + @this_user = User.find_by_display_name(params[:display_name]) + end + end diff --git a/app/models/diary_entry.rb b/app/models/diary_entry.rb index 2da92d400..ad334151c 100644 --- a/app/models/diary_entry.rb +++ b/app/models/diary_entry.rb @@ -1,2 +1,3 @@ class DiaryEntry < ActiveRecord::Base + belongs_to :user end diff --git a/app/models/user.rb b/app/models/user.rb index 780e0caaf..7befa479a 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -3,6 +3,7 @@ class User < ActiveRecord::Base require 'digest/md5' has_many :traces + has_many :diary_entries validates_confirmation_of :pass_crypt, :message => 'Password must match the confirmation password' validates_uniqueness_of :display_name, :allow_nil => true diff --git a/app/views/diary_entry/_diary_entry.rhtml b/app/views/diary_entry/_diary_entry.rhtml new file mode 100644 index 000000000..cf9115f6c --- /dev/null +++ b/app/views/diary_entry/_diary_entry.rhtml @@ -0,0 +1,3 @@ +<%= diary_entry.title %>
+<%= simple_format(diary_entry.body) %> +
diff --git a/app/views/diary_entry/new.rhtml b/app/views/diary_entry/new.rhtml new file mode 100644 index 000000000..ead58944c --- /dev/null +++ b/app/views/diary_entry/new.rhtml @@ -0,0 +1,7 @@ +<%= error_messages_for 'diary_entry' %> + +<%= start_form_tag :controller => 'diary_entry', :action => 'new' %> +subject<%= text_field 'diary_entry', 'title' %>
+body<%= text_area 'diary_entry', 'body' %>
+ <%= submit_tag 'Save' %> +<% end_form_tag %> diff --git a/app/views/user/diary.rhtml b/app/views/user/diary.rhtml new file mode 100644 index 000000000..abe896db9 --- /dev/null +++ b/app/views/user/diary.rhtml @@ -0,0 +1,8 @@ +

<%= @this_user.display_name %>'s diary

+<% if @this_user.id == @user.id %> + <%= link_to 'new post', :controller => 'diary_entry', :action => 'new', :display_name => @user.display_name %> +<% end %> + +

recent posts:

+FIXME: geoRSS needed

+<%= render :partial => 'diary_entry/diary_entry', :collection => @this_user.diary_entries %> diff --git a/app/views/user/new.rhtml b/app/views/user/new.rhtml index 681182321..e1222c64e 100644 --- a/app/views/user/new.rhtml +++ b/app/views/user/new.rhtml @@ -12,7 +12,8 @@ By creating an account, you agree that all work uploaded to openstreetmap.org an password:<%= password_field('user', 'pass_crypt',{:size => 50, :maxlength => 255}) %> retype password:<%= password_field('user', 'pass_crypt_confirmation',{:size => 50, :maxlength => 255}) %> - +
+FIXME OL map so people can submit where they live
diff --git a/app/views/user/view.rhtml b/app/views/user/view.rhtml new file mode 100644 index 000000000..34a30dd42 --- /dev/null +++ b/app/views/user/view.rhtml @@ -0,0 +1,13 @@ +

<%= @this_user.display_name %>

+<% if @this_user.id == @user.id %> + <%= link_to 'go to your account page', :controller => 'user', :action => 'account', :display_name => @user.display_name %>

+<% else %> + <%= link_to 'send message', :controller => 'user', :action => 'message', :display_name => @user.display_name %>

| + <%= link_to 'Add as friend', :controller => 'user', :action => 'make_friend', :display_name => @user.display_name %>

+<% end %> + +<%= link_to 'diary', :controller => 'user', :action => 'diary', :display_name => @user.display_name %>

+ +<%= simple_format(@this_user.description) %> + + diff --git a/config/routes.rb b/config/routes.rb index 8bfc36388..ff42dbfa4 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -55,7 +55,8 @@ ActionController::Routing::Routes.draw do |map| # user pages map.connect '/user/:display_name', :controller => 'user', :action => 'view' - map.connect '/user/:display_name/diary', :controller => 'diary', :action => 'view' + map.connect '/user/:display_name/diary', :controller => 'user', :action => 'diary' + map.connect '/user/:display_name/diary/newpost', :controller => 'diary_entry', :action => 'new' map.connect '/user/:display_name/edit', :controller => 'user', :action => 'edit' map.connect '/user/:display_name/account', :controller => 'user', :action => 'account' diff --git a/db/migrate.sql b/db/migrate.sql index 6f7266cef..dc81e5d0c 100644 --- a/db/migrate.sql +++ b/db/migrate.sql @@ -36,3 +36,8 @@ alter table gpx_files drop column tmpname; alter table users add column description text not null; create table diary_entries(id bigint not null auto_increment, user_id bigint not null, title varchar(255), body text, primary key(id)); +alter table diary_entries add created_at datetime; +alter table diary_entries add updated_at datetime; + + +