Skip to content

Commit

Permalink
Adds generic RecordNotFound 404 handling on raises in controllers (Ap…
Browse files Browse the repository at this point in the history
…plicationController). Modifies the search pattern, again, for default ajax selectors.
  • Loading branch information
mjy committed Nov 7, 2014
1 parent 6b12114 commit f49305c
Show file tree
Hide file tree
Showing 21 changed files with 26 additions and 32 deletions.
7 changes: 7 additions & 0 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ class ApplicationController < ActionController::Base
# Prevent CSRF attacks by raising an exception.
# For APIs, you may want to use :null_session instead.
protect_from_forgery with: :exception
rescue_from ActiveRecord::RecordNotFound, with: :record_not_found

include Workbench::SessionsHelper
include ProjectsHelper
Expand Down Expand Up @@ -65,5 +66,11 @@ def meta_data
def site_name
@site_name ||= 'TaxonWorks'
end

private

def record_not_found
render plain: "404 Not Found", status: 404
end

end
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ module DataControllerConfiguration::ProjectDataControllerConfiguration
extend ActiveSupport::Concern

included do
include DataControllerConfiguration

include DataControllerConfiguration
before_action :require_sign_in_and_project_selection
end

Expand Down
2 changes: 0 additions & 2 deletions app/controllers/images_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,6 @@ def search
end
end



def autocomplete
@images = Image.find_for_autocomplete(params.merge(project_id: sessions_current_project_id)) # in model

Expand Down
2 changes: 1 addition & 1 deletion app/views/collecting_events/_quick_search_form.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<%= form_tag(search_collecting_events_path) do %>
<%= form_tag(search_collecting_events_path, {method: :get}) do %>
<%= render partial: 'workbench/elements/forms/ajax_select',
locals: {controller: 'collecting_events',
object: nil,
Expand Down
2 changes: 1 addition & 1 deletion app/views/collection_objects/_quick_search_form.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<%= form_tag(search_collection_objects_path) do %>
<%= form_tag(search_collection_objects_path, {method: :get}) do %>
<%= render partial: 'workbench/elements/forms/ajax_select',
locals: {controller: 'collection_objects',
object: nil,
Expand Down
2 changes: 1 addition & 1 deletion app/views/contents/_quick_search_form.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<%= form_tag(search_contents_path) do %>
<%= form_tag(search_contents_path, {method: :get}) do %>
<%= render partial: 'workbench/elements/forms/ajax_select',
locals: {controller: 'contents',
object: nil,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<%= form_tag(search_controlled_vocabulary_terms_path) do %>
<%= form_tag(search_controlled_vocabulary_terms_path, {method: :get}) do %>
<%= render partial: 'workbench/elements/forms/ajax_select',
locals: {controller: 'controlled_vocabulary_terms',
object: nil,
Expand Down
2 changes: 1 addition & 1 deletion app/views/geographic_areas/_quick_search_form.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<%= form_tag(search_geographic_areas_path) do %>
<%= form_tag(search_geographic_areas_path, {method: :get}) do %>
<%= render partial: 'workbench/elements/forms/ajax_select',
locals: {controller: 'geographic_areas',
object: nil,
Expand Down
2 changes: 1 addition & 1 deletion app/views/images/_quick_search_form.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<%= form_tag(search_images_path) do %>
<%= form_tag(search_images_path, {method: :get}) do %>
<%= render partial: 'workbench/elements/forms/ajax_select',
locals: {controller: 'images',
object: nil,
Expand Down
2 changes: 1 addition & 1 deletion app/views/loans/_quick_search_form.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<%= form_tag(search_loans_path) do %>
<%= form_tag(search_loans_path, {method: :get}) do %>
<%= render partial: 'workbench/elements/forms/ajax_select',
locals: {controller: 'loans',
object: 'loan',
Expand Down
2 changes: 1 addition & 1 deletion app/views/namespaces/_quick_search_form.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<%= form_tag(search_namespaces_path) do %>
<%= form_tag(search_namespaces_path, {method: :go}) do %>
<%= render partial: 'workbench/elements/forms/ajax_select',
locals: {controller: 'namespaces',
object: nil,
Expand Down
2 changes: 1 addition & 1 deletion app/views/otus/_quick_search_form.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<%= form_tag(search_otus_path) do %>
<%= form_tag(search_otus_path, {method: :get}) do %>
<%= render partial: 'workbench/elements/forms/ajax_select',
locals: {controller: 'otus',
object: nil,
Expand Down
2 changes: 1 addition & 1 deletion app/views/people/_quick_search_form.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<%= form_tag(search_people_path) do %>
<%= form_tag(search_people_path, {method: :get}) do %>
<%= render partial: 'workbench/elements/forms/ajax_select',
locals: {controller: 'people',
object: nil,
Expand Down
2 changes: 1 addition & 1 deletion app/views/projects/_quick_search_form.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<%= form_tag(search_projects_path) do %>
<%= form_tag(search_projects_path, {method: :get}) do %>
<%= render partial: 'workbench/elements/forms/ajax_select',
locals: {controller: 'projects',
object: nil,
Expand Down
2 changes: 1 addition & 1 deletion app/views/repositories/_quick_search_form.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<%= form_tag(search_repositories_path) do %>
<%= form_tag(search_repositories_path, {method: :get}) do %>
<%= render partial: 'workbench/elements/forms/ajax_select',
locals: {controller: 'repositories',
object: nil,
Expand Down
2 changes: 1 addition & 1 deletion app/views/sources/_quick_search_form.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<%= form_tag(search_sources_path) do %>
<%= form_tag(search_sources_path, {method: :get}) do %>
<%= render partial: 'workbench/elements/forms/ajax_select',
locals: {controller: 'sources',
object: nil,
Expand Down
2 changes: 1 addition & 1 deletion app/views/tags/_quick_search_form.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<%= form_tag(search_tags_path) do %>
<%= form_tag(search_tags_path, {method: :get}) do %>
<%= render partial: 'workbench/elements/forms/ajax_select',
locals: {controller: 'tags',
object: nil,
Expand Down
2 changes: 1 addition & 1 deletion app/views/taxon_names/_quick_search_form.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<%= form_tag(search_taxon_names_path) do %>
<%= form_tag(search_taxon_names_path, method: :get) do %>
<%= render partial: 'workbench/elements/forms/ajax_select',
locals: {controller: 'taxon_names',
object: nil,
Expand Down
2 changes: 1 addition & 1 deletion app/views/type_materials/_quick_search_form.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<%= form_tag(search_type_materials_path) do %>
<%= form_tag(search_type_materials_path, {method: :get}) do %>
<%= render partial: 'workbench/elements/forms/ajax_select',
locals: {controller: 'type_materials',
object: nil,
Expand Down
10 changes: 0 additions & 10 deletions bd

This file was deleted.

4 changes: 2 additions & 2 deletions config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
TaxonWorks::Application.routes.draw do

# Vetted / tested

# All models that use data controllers should include this concern.
# See http://api.rubyonrails.org/classes/ActionDispatch/Routing/Mapper/Concerns.html to extend it to take options if need be.
Expand All @@ -11,8 +10,8 @@
get 'list'
post 'batch_create'
post 'batch_preview'
post 'search'
get 'autocomplete'
get 'search'
end
end

Expand Down Expand Up @@ -224,4 +223,5 @@
# # (app/controllers/admin/products_controller.rb)
# resources :products
# end
#
end

0 comments on commit f49305c

Please sign in to comment.