Make per-user diary entry lists go through the diary_entry controller so
that we aren't duplicating everything in the user controller. This also makes per-user RSS feeds work, and makes links to specific posts work properly so that the RSS feeds behave sensibly.
This commit is contained in:
parent
f0b5776389
commit
1017c4c39a
6 changed files with 37 additions and 27 deletions
|
@ -10,26 +10,41 @@ class DiaryEntryController < ApplicationController
|
|||
@entry = DiaryEntry.new(params[:diary_entry])
|
||||
@entry.user = @user
|
||||
if @entry.save
|
||||
redirect_to :controller => 'user', :action => 'diary', :display_name => @user.display_name
|
||||
redirect_to :controller => 'diary_entry', :action => 'list', :display_name => @user.display_name
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def list
|
||||
@title = 'recent diary entries'
|
||||
@entries=DiaryEntry.find(:all, :order => 'created_at DESC', :limit=>20)
|
||||
if params[:display_name]
|
||||
@this_user = User.find_by_display_name(params[:display_name])
|
||||
@title = @this_user.display_name + "'s diary"
|
||||
if params[:id]
|
||||
@entries=DiaryEntry.find(:all, :conditions => ['user_id = ? AND id = ?', @this_user.id, params[:id]])
|
||||
else
|
||||
@entries=DiaryEntry.find(:all, :conditions => ['user_id = ?', @this_user.id], :order => 'created_at DESC')
|
||||
end
|
||||
else
|
||||
@title = 'recent diary entries'
|
||||
@entries=DiaryEntry.find(:all, :order => 'created_at DESC', :limit => 20)
|
||||
end
|
||||
end
|
||||
|
||||
def rss
|
||||
@entries=DiaryEntry.find(:all, :order => 'created_at DESC', :limit=>20)
|
||||
|
||||
rss = OSM::GeoRSS.new('OpenStreetMap diary entries', 'Recent diary entries from users of OpenStreetMap', 'http://www.openstreetmap.org/diary')
|
||||
if params[:display_name]
|
||||
@this_user = User.find_by_display_name(params[:display_name])
|
||||
@entries=DiaryEntry.find(:all, :conditions => ['user_id = ?', @this_user.id], :order => 'created_at DESC', :limit => 20)
|
||||
rss = OSM::GeoRSS.new("OpenStreetMap diary entries for #{@this_user.display_name}", "Recent OpenStreetmap diary entries from #{@this_user.display_name}", "http://www.openstreetmap.org/user/#{@this_user.display_name}/diary")
|
||||
else
|
||||
@entries=DiaryEntry.find(:all, :order => 'created_at DESC', :limit => 20)
|
||||
rss = OSM::GeoRSS.new('OpenStreetMap diary entries', 'Recent diary entries from users of OpenStreetMap', 'http://www.openstreetmap.org/diary')
|
||||
end
|
||||
|
||||
@entries.each do |entry|
|
||||
# add geodata here
|
||||
latitude = nil
|
||||
longitude = nil
|
||||
rss.add(latitude, longitude, entry.title, url_for({:controller => 'user', :action => 'diary', :id => entry.id, :display_name => entry.user.display_name}), entry.body, entry.created_at)
|
||||
rss.add(latitude, longitude, entry.title, url_for({:controller => 'diary_entry', :action => 'list', :id => entry.id, :display_name => entry.user.display_name}), entry.body, entry.created_at)
|
||||
end
|
||||
|
||||
response.headers["Content-Type"] = 'application/rss+xml'
|
||||
|
|
|
@ -186,11 +186,6 @@ class UserController < ApplicationController
|
|||
@title = @this_user.display_name
|
||||
end
|
||||
|
||||
def diary
|
||||
@this_user = User.find_by_display_name(params[:display_name])
|
||||
@title = @this_user.display_name + "'s diary"
|
||||
end
|
||||
|
||||
def make_friend
|
||||
|
||||
if params[:display_name]
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<b><%= diary_entry.title %></b><br />
|
||||
<%= simple_format(diary_entry.body) %>
|
||||
Posted by user <b><%= link_to diary_entry.user.display_name,{:controller => 'user', :action=>'diary', :display_name => diary_entry.user.display_name} %></b> at <%= diary_entry.created_at %><br />
|
||||
Posted by user <b><%= link_to diary_entry.user.display_name,{:controller => 'diary_entry', :action => 'list', :display_name => diary_entry.user.display_name} %></b> at <%= diary_entry.created_at %><br />
|
||||
<br />
|
||||
<hr />
|
||||
|
|
|
@ -1,6 +1,14 @@
|
|||
<% if @this_user %>
|
||||
<h2><%= @this_user.display_name %>'s diary</h2>
|
||||
|
||||
<% if @user and @this_user.id == @user.id %>
|
||||
<%= link_to 'new post', :controller => 'diary_entry', :action => 'new', :display_name => @user.display_name %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
|
||||
<h3>Recent diary entries:</h3>
|
||||
<br />
|
||||
|
||||
<%= render :partial => 'diary_entry/diary_entry', :collection => @entries %>
|
||||
|
||||
<%= link_to(image_tag("RSS.gif", :size => "16x16", :border => 0), :action => 'rss') %>
|
||||
<%= auto_discovery_link_tag(:atom, :action => 'rss') %>
|
||||
<%= auto_discovery_link_tag(:atom, :action => 'rss') %>
|
||||
|
|
|
@ -1,8 +0,0 @@
|
|||
<h2><%= @this_user.display_name %>'s diary</h2>
|
||||
<% if @user and @this_user.id == @user.id %>
|
||||
<%= link_to 'new post', :controller => 'diary_entry', :action => 'new', :display_name => @user.display_name %>
|
||||
<% end %>
|
||||
|
||||
<h3>recent posts:</h3>
|
||||
<br><br>
|
||||
<%= render :partial => 'diary_entry/diary_entry', :collection => @this_user.diary_entries %>
|
|
@ -3,8 +3,8 @@
|
|||
|
||||
<% if @user and @this_user.id == @user.id %>
|
||||
<h3>Your diary</h3>
|
||||
<%= link_to 'View your diary', :controller => 'user', :action=>'diary', :display_name => @user.display_name %><br/>
|
||||
<%= link_to 'New diary post', :controller => 'diary_entry', :action=>'new', :display_name => @user.display_name %>
|
||||
<%= link_to 'View your diary', :controller => 'diary_entry', :action => 'list', :display_name => @user.display_name %><br/>
|
||||
<%= link_to 'New diary post', :controller => 'diary_entry', :action => 'new', :display_name => @user.display_name %>
|
||||
|
||||
<h3>Your traces</h3>
|
||||
<%= link_to 'View your traces', :controller => 'trace', :action=>'mine' %>
|
||||
|
@ -16,8 +16,8 @@
|
|||
<% else %>
|
||||
<%= link_to 'Send message', :controller => 'message', :action => 'new', :user_id => @this_user.id %><br />
|
||||
<%= link_to 'Add as friend', :controller => 'user', :action => 'make_friend', :display_name => @this_user.display_name %><br />
|
||||
<%= link_to 'View diary', :controller => 'user', :action=>'diary', :display_name => @this_user.display_name %><br />
|
||||
<%= link_to 'View traces', :controller => 'trace', :action=>'view', :display_name => @this_user.display_name %>
|
||||
<%= link_to 'View diary', :controller => 'diary_entry', :action => 'user', :display_name => @this_user.display_name %><br />
|
||||
<%= link_to 'View traces', :controller => 'trace', :action => 'view', :display_name => @this_user.display_name %>
|
||||
|
||||
<% end %>
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue