Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Show only the classifieds belonging to the member.

  • Loading branch information...
commit 84ad3df95272ee4409e9f8fe4e38723670dbd9e4 1 parent 21b5a25
@alloy alloy authored
View
10 app/controllers/classifieds_controller.rb
@@ -1,10 +1,10 @@
class ClassifiedsController < ApplicationController
- allow_access(:authenticated, :only => [:new, :create])
+ allow_access(:authenticated, :only => [:index, :new, :create])
allow_access(:authenticated, :only => [:edit, :update, :destroy]) { !find_classified.nil? }
- allow_access(:all, :only => :index)
+ allow_access(:all, :only => :index) { !my_classifieds? } # visitors have no `my classifieds'
def index
- @classifieds = Classified.all
+ @classifieds = my_classifieds? ? @authenticated.classifieds : Classified.all
end
def new
@@ -35,6 +35,10 @@ def destroy
private
+ def my_classifieds?
+ params[:show] == :mine
+ end
+
def find_classified
@classified = @authenticated.classifieds.find_by_id(params[:id])
end
View
2  app/views/classifieds/_classified.html.erb
@@ -1,6 +1,6 @@
<div class="<%= classified_classes(classified, classified_counter) %>">
<div class="inner">
- <h2><%= classified.title %></h2>
+ <h2><%= classified.title %> <%= link_to('(edit)', edit_classified_path(classified)) if classified.placer == @authenticated %></h2>
<p class="description"><%= classified.description %></p>
<p>
<% if classified.offered? %>
View
2  app/views/classifieds/edit.html.erb
@@ -1,4 +1,4 @@
-y<h1><%= @title = 'Update your classified' %></h1>
+<h1><%= @title = 'Update your classified' %></h1>
<%= render :partial => 'form' %>
View
5 app/views/classifieds/index.html.erb
@@ -2,6 +2,11 @@
<%= @title = 'Classifieds' %>
<% if @authenticated %>
<%= link_to 'Post to classifieds', new_classified_path %>
+ <% if @authenticated.classifieds.empty? %>
+ <span>My classifieds</span>
+ <% else %>
+ <%= link_to 'My classifieds', my_classifieds_path %>
+ <% end %>
<% else %>
<span>Join and sign in to post classifieds</span>
<% end %>
View
9 config/routes.rb
@@ -1,8 +1,9 @@
Appsterdam::Application.routes.draw do
- match '/members/create' => 'members#create', :as => :create_members
- match '/session' => 'sessions#create', :as => :session
- match '/session/clear' => 'sessions#clear', :as => :clear_session
-
+ match '/members/create' => 'members#create', :as => :create_members
+ match '/session' => 'sessions#create', :as => :session
+ match '/session/clear' => 'sessions#clear', :as => :clear_session
+ match '/classifieds/mine' => 'classifieds#index', :as => :my_classifieds, :show => :mine
+
resources :classifieds
resources :members do
resources :spam_reports
View
3  public/stylesheets/global.css
@@ -796,6 +796,7 @@ div.member:hover li.report a
#page-classifieds h1 a,
#page-classifieds h1 span
{
+ margin-left: 10px;
float: right;
font-size: 14px;
}
@@ -822,4 +823,4 @@ div.classified.omega .inner
div.classified .description
{
margin: 16px 0 8px 0;
-}
+}
View
8 test/functional/classifieds_controller_test.rb
@@ -8,6 +8,7 @@
assigns(:classifieds).should == Classified.all
end
+ should.require_login.get :index, :show => :mine
should.require_login.get :new
should.require_login.post :create
should.require_login.get :edit, :id => classifieds(:house)
@@ -20,6 +21,13 @@
login(members(:developer))
end
+ it "sees an overview of her own ads" do
+ get :index, :show => :mine
+ status.should.be :ok
+ template.should.be 'classifieds/index'
+ assigns(:classifieds).should == [classifieds(:bike)]
+ end
+
it "sees a form to create a new ad" do
get :new
status.should.be :ok
Please sign in to comment.
Something went wrong with that request. Please try again.