diff options
author | Louise Crow <louise.crow@gmail.com> | 2014-11-07 17:12:54 +0000 |
---|---|---|
committer | Louise Crow <louise.crow@gmail.com> | 2014-12-18 14:03:50 +0000 |
commit | 16eebb4d30871f5457816d0af925d038715f4757 (patch) | |
tree | 045165f83e186b692490ab9e34f74072533146a8 | |
parent | f5e430100e1696d7b7c2703394e2190a91be41bd (diff) |
RESTful routing for admin track actions
-rw-r--r-- | app/controllers/admin_track_controller.rb | 12 | ||||
-rw-r--r-- | app/controllers/admin_user_controller.rb | 7 | ||||
-rw-r--r-- | app/views/admin_general/_admin_navbar.html.erb | 2 | ||||
-rw-r--r-- | app/views/admin_track/_some_tracks.html.erb | 3 | ||||
-rw-r--r-- | app/views/admin_track/index.html.erb (renamed from app/views/admin_track/list.html.erb) | 0 | ||||
-rw-r--r-- | config/routes.rb | 7 | ||||
-rw-r--r-- | spec/controllers/admin_track_controller_spec.rb | 7 |
7 files changed, 20 insertions, 18 deletions
diff --git a/app/controllers/admin_track_controller.rb b/app/controllers/admin_track_controller.rb index 085c9c6cc..63ee5c12e 100644 --- a/app/controllers/admin_track_controller.rb +++ b/app/controllers/admin_track_controller.rb @@ -5,7 +5,8 @@ # Email: hello@mysociety.org; WWW: http://www.mysociety.org/ class AdminTrackController < AdminController - def list + + def index @query = params[:query] if @query track_things = TrackThing.where(["lower(track_query) like lower('%'||?||'%')", @query]) @@ -13,7 +14,14 @@ class AdminTrackController < AdminController track_things = TrackThing end @admin_tracks = track_things.paginate :order => "created_at desc", :page => params[:page], :per_page => 100 - @popular = ActiveRecord::Base.connection.select_all("select count(*) as count, title, info_request_id from track_things join info_requests on info_request_id = info_requests.id where info_request_id is not null group by info_request_id, title order by count desc limit 10;") + @popular = ActiveRecord::Base.connection.select_all("select count(*) as count, title, info_request_id from track_things join info_requests on info_request_id = info_requests.id where info_request_id is not null group by info_request_id, title order by count desc limit 10;") + end + + def destroy + track_thing = TrackThing.find(params[:id].to_i) + track_thing.destroy + flash[:notice] = 'Track destroyed' + redirect_to admin_user_url(track_thing.tracking_user) end private diff --git a/app/controllers/admin_user_controller.rb b/app/controllers/admin_user_controller.rb index bbb5d002a..7ef461594 100644 --- a/app/controllers/admin_user_controller.rb +++ b/app/controllers/admin_user_controller.rb @@ -55,13 +55,6 @@ class AdminUserController < AdminController @admin_user = User.find(params[:id]) end - def destroy_track - track_thing = TrackThing.find(params[:track_id].to_i) - track_thing.destroy - flash[:notice] = 'Track destroyed' - redirect_to admin_user_url(track_thing.tracking_user) - end - def clear_bounce user = User.find(params[:id]) user.email_bounced_at = nil diff --git a/app/views/admin_general/_admin_navbar.html.erb b/app/views/admin_general/_admin_navbar.html.erb index 5dab81e7d..62982b3f1 100644 --- a/app/views/admin_general/_admin_navbar.html.erb +++ b/app/views/admin_general/_admin_navbar.html.erb @@ -13,7 +13,7 @@ <li><%= link_to 'Categories', admin_categories_path %></li> <li><%= link_to 'Requests', admin_requests_path %></li> <li><%= link_to 'Users', admin_users_path %></li> - <li><%= link_to 'Tracks', admin_track_list_path %></li> + <li><%= link_to 'Tracks', admin_tracks_path %></li> <li><%= link_to 'Log out', signout_path %></li> </ul> </div> diff --git a/app/views/admin_track/_some_tracks.html.erb b/app/views/admin_track/_some_tracks.html.erb index e1bceee85..c17350e4b 100644 --- a/app/views/admin_track/_some_tracks.html.erb +++ b/app/views/admin_track/_some_tracks.html.erb @@ -32,9 +32,8 @@ <% if include_destroy %> <tr> <td colspan="2"> - <%= form_tag destroy_track_admin_user_path(track_thing.tracking_user), :class => "form form-inline admin-table-form" do %> + <%= form_tag admin_track_path(track_thing), :method => 'delete', :class => "form form-inline admin-table-form" do %> <div> - <%= hidden_field_tag 'track_id', track_thing.id %> <%= submit_tag "Destroy track", :class => "btn btn-warning" %> </div> <% end %> diff --git a/app/views/admin_track/list.html.erb b/app/views/admin_track/index.html.erb index 2b1dc5737..2b1dc5737 100644 --- a/app/views/admin_track/list.html.erb +++ b/app/views/admin_track/index.html.erb diff --git a/config/routes.rb b/config/routes.rb index 34e3cd590..529f044e7 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -277,7 +277,6 @@ Alaveteli::Application.routes.draw do get 'banned', :on => :collection get 'show_bounce_message', :on => :member post 'clear_bounce', :on => :member - post 'destroy_track', :on => :member post 'login_as', :on => :member post 'clear_profile_photo', :on => :member post 'modify_comment_visibility', :on => :collection @@ -286,7 +285,11 @@ Alaveteli::Application.routes.draw do #### #### AdminTrack controller - match '/admin/track/list' => 'admin_track#list', :as => :admin_track_list + scope '/admin', :as => 'admin' do + resources :tracks, + :controller => 'admin_track', + :only => [:index, :destroy] + end #### #### AdminCensorRule controller diff --git a/spec/controllers/admin_track_controller_spec.rb b/spec/controllers/admin_track_controller_spec.rb index f2de6c0d3..d29db4966 100644 --- a/spec/controllers/admin_track_controller_spec.rb +++ b/spec/controllers/admin_track_controller_spec.rb @@ -1,9 +1,8 @@ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') describe AdminTrackController, "when administering tracks" do - render_views - - it "shows the list page" do - get :list + + it "shows the index page" do + get :index end end |