Permalink
Browse files

Changes in Routes /me /user/:id/headlines /headline/:id

  • Loading branch information...
1 parent ce8c31e commit 597a7721c1196435b53495f07837b948fd2dc0c3 @raphaelharboun committed Mar 27, 2012
@@ -11,6 +11,7 @@
index do
column :id
+ column :username
column :email
column "headlines" do |user|
link_to "#{user.headlines.count} headlines", admin_user_path(user)
@@ -4,4 +4,8 @@
#print-headline {
margin-top: 45px;
+}
+
+.right {
+ float:right;
}
@@ -1,8 +1,13 @@
class ApplicationController < ActionController::Base
protect_from_forgery
+ rescue_from ActiveRecord::RecordNotFound, :with => :record_not_found
def after_sign_in_path_for(resource)
root_path
end
+
+ def record_not_found
+ render :text => "404 Not Found", :status => 404
+ end
end
@@ -2,7 +2,8 @@
class HeadlinesController < ApplicationController
- before_filter :authenticate_user!, :except => [:new, :index, :show]
+ before_filter :authenticate_user!, :except => [:new, :index, :show, :evening_index]
+
# GET /
# GET /headlines
@@ -26,11 +27,10 @@ def create
# GET /user/:id/headlines
def index
- begin
- @user = User.find(params[:id])
- rescue
- render :text => "User not found" and return
- end
+ @user = User.find(params[:id])
+
+ redirect_to devine_headlines_path if @user.type == "DevineUser"
+
@headlines = @user.headlines.order("created_at DESC")
current = @headlines.select { |h| h.created_at >= Headline.get_start_date }
unless current.empty?
@@ -39,6 +39,11 @@ def index
end
end
+ # GET /headlines/:id
+ def show
+ @headline = Headline.history.find(params[:id])
+ end
+
# GET /me/headlines
def me_index
@headlines = current_user.headlines.order("created_at DESC")
@@ -51,23 +56,23 @@ def me_index
end
# GET /me/current
- def show_current
+ def me_current_show
if @current_headline = current_user.headlines.current.first then
@statistics = @current_headline.get_statistics
else
redirect_to "/me/headlines"
end
end
- # GET /user/:id/headlines/:id
- def show
- if params[:user_id] then
- render :text => "public headline"
- elsif current_user
- render :text => "private headline"
- else
- redirect_to user_session_path
- end
+ #GET /eveningstandard/headlines
+ def evening_index
+ devine = DevineUser.first
+ @headlines = devine.headlines.order("created_at DESC")
+ end
+
+ #GET /eveningstandard/headline/:id
+ def evening_show
+ @headline = DevineUser.first.headlines.find(params[:id])
end
@@ -1,7 +1,7 @@
class DevineUser < User
def get_last_headlines(n)
- headlines.order("created_at DESC").limit(n).select("name, created_at")
+ headlines.order("created_at DESC").limit(n).select("id, name, created_at")
end
end
@@ -37,7 +37,7 @@ def extract_tags
def get_statistics
tag_count = Tag.current.sum("count").to_f
- average_length = (Headline.current.map { |h| h.tags.count }).inject { |sum,t| sum + t}
+ average_length = (Headline.current.map { |h| h.tags.count }).inject { |sum,t| sum + t} / Headline.current.count
return {:tag_count => tag_count, :average_length => average_length}
end
@@ -11,7 +11,7 @@ class User < ActiveRecord::Base
:confirmable
# Setup accessible (or protected) attributes for your model
- attr_accessible :email, :password, :password_confirmation, :remember_me, :type
+ attr_accessible :email, :password, :password_confirmation, :remember_me, :type, :username
def has_current_headline?
!headlines.current.empty?
Binary file not shown.
@@ -1,21 +1,18 @@
<h2>Edit <%= resource_name.to_s.humanize %></h2>
-<%= form_for(resource, :as => resource_name, :url => registration_path(resource_name), :html => { :method => :put }) do |f| %>
+<%= simple_form_for(resource, :as => resource_name, :url => registration_path(resource_name), :html => { :method => :put }) do |f| %>
<%= devise_error_messages! %>
-
- <div><%= f.label :email %><br />
- <%= f.email_field :email %></div>
-
- <div><%= f.label :password %> <i>(leave blank if you don't want to change it)</i><br />
- <%= f.password_field :password %></div>
-
- <div><%= f.label :password_confirmation %><br />
- <%= f.password_field :password_confirmation %></div>
-
- <div><%= f.label :current_password %> <i>(we need your current password to confirm your changes)</i><br />
- <%= f.password_field :current_password %></div>
-
- <div><%= f.submit "Update" %></div>
+ <fieldset>
+ <legend>Edit</legend>
+ <%= f.input :email %>
+ <%= f.input :username %>
+ <%= f.input :password %>
+ <%= f.input :password_confirmation %>
+ <%= f.input :current_password %>
+ <div class="form-actions">
+ <%= f.button :submit, "Update" %>
+ </div>
+ </fieldset>
<% end %>
<h3>Cancel my account</h3>
@@ -2,6 +2,7 @@
<fieldset>
<legend>Sign Up</legend>
<%= f.input :email %>
+ <%= f.input :username %>
<%= f.input :password %>
<%= f.input :password_confirmation %>
<div class="form-actions">
@@ -1,4 +0,0 @@
-<div class="hero-unit">
- <p>Your next issue headline :</p>
- <h1><%= link_to @current_headline.name, me_current_headline_path %></h1>
-</div>
@@ -0,0 +1,4 @@
+<div class="hero-unit">
+ <p>Your next issue headline :</p>
+ <h1><%= link_to @current_headline.name, me_current_path %></h1>
+</div>
@@ -8,11 +8,12 @@
<table class="table">
<% @last_devine_headlines.each do |headline| %>
<tr>
- <td><%= link_to headline.name, "#" %></td>
+ <td><%= link_to headline.name, devine_headline_path(headline) %></td>
<td><%= headline.created_at.to_formatted_s(:rfc822) %></td>
</tr>
<% end %>
</table>
+ <%= link_to "view all", devine_headlines_path, :class => "right" %>
</div>
<div class="span6">
<h2>Twitter Trends <small>London</small> </h2>
@@ -0,0 +1,22 @@
+<div class="page-header">
+ <h1>Last issue's headlines</h1>
+</div>
+
+<div class="row">
+ <div class="span6">
+ <table class="table">
+ <thead>
+ <tr>
+ <th>name</th>
+ <th>date</th>
+ </tr>
+ </thead>
+ <% @headlines.each do |headline| %>
+ <tr>
+ <td><%= link_to headline.name, devine_headline_path(headline) %></td>
+ <td><%= headline.created_at.to_formatted_s(:rfc822) %></td>
+ </tr>
+ <% end %>
+ </table>
+ </div>
+</div>
@@ -0,0 +1 @@
+<%= @headline.name %>
@@ -1,12 +1,12 @@
<% if @current_headline then %>
- <%= render "currentHeadline" %>
+ <%= render "current_headline" %>
<% end %>
<h2>Previous Headlines</h2>
<table class="table table-striped">
<% @headlines.each do |headline| %>
<tr>
- <td><%= link_to headline.name, current_page?(:action => 'me_index') ? me_headline_path(headline) : user_headline_path(@user,headline) %></td>
+ <td><%= link_to headline.name, headline_path(headline) %></td>
<td><%= link_to headline.created_at, "#" %></td>
<td></td>
</tr>
@@ -0,0 +1 @@
+<%= @headline.name %>
@@ -20,11 +20,14 @@
match "/" => "headlines#create", :via => :post, :as => :new_index_headline
scope "me" do
match "headlines" => "headlines#me_index", :via => :get, :as => :me_headlines
- match "current" => "headlines#show_current", :via => :get, :as => :me_current_headline
- match "headline/:id" => "headlines#show", :via => :get, :as => :me_headline
+ match "current" => "headlines#me_current_show", :via => :get, :as => :me_current
+ end
+ scope "eveningstandard" do
+ match "headlines" => "headlines#evening_index", :via => :get, :as => :devine_headlines
+ match "headline/:id" => "headlines#evening_show", :via => :get, :as => :devine_headline
end
match "user/:id/headlines" => "headlines#index", :via => :get, :as => :user_headlines
- match "user/:user_id/headline/:headline_id" => "headlines#show", :via => :get, :as => :user_headline
+ match "headline/:id" => "headlines#show", :via => :get, :as => :headline
root :to => "Headlines#new"
@@ -0,0 +1,6 @@
+class AddUsernameToUsers < ActiveRecord::Migration
+ def change
+ add_column :users, :username, :string
+
+ end
+end
View
@@ -11,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.
-ActiveRecord::Schema.define(:version => 20120325182206) do
+ActiveRecord::Schema.define(:version => 20120326182904) do
create_table "active_admin_comments", :force => true do |t|
t.string "resource_id", :null => false
@@ -84,6 +84,7 @@
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.string "type", :default => "User"
+ t.string "username"
end
add_index "users", ["confirmation_token"], :name => "index_users_on_confirmation_token", :unique => true
Oops, something went wrong.

0 comments on commit 597a772

Please sign in to comment.