aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--app/controllers/file_request_controller.rb18
-rw-r--r--app/helpers/application_helper.rb27
-rw-r--r--app/views/file_request/create.rhtml5
-rw-r--r--app/views/file_request/index.rhtml2
-rw-r--r--config/environment.rb6
5 files changed, 45 insertions, 13 deletions
diff --git a/app/controllers/file_request_controller.rb b/app/controllers/file_request_controller.rb
index 2bcab9ea9..b96a87b8b 100644
--- a/app/controllers/file_request_controller.rb
+++ b/app/controllers/file_request_controller.rb
@@ -4,26 +4,20 @@
# Copyright (c) 2007 UK Citizens Online Democracy. All rights reserved.
# Email: francis@mysociety.org; WWW: http://www.mysociety.org/
#
-# $Id: file_request_controller.rb,v 1.2 2007-08-21 11:33:45 francis Exp $
+# $Id: file_request_controller.rb,v 1.3 2007-08-23 17:39:42 francis Exp $
class FileRequestController < ApplicationController
def index
- respond_to do |format|
- format.html
- end
end
def create
@info_request = InfoRequest.new(params[:info_request])
- @info_request.save
-
- #redirect_to(:action => 'index')
- render :action => 'index'
-
-# respond_to do |format|
-# format.html
-# end
+ if not @info_request.save
+ render :action => 'index'
+ else
+ # render create action
+ end
end
diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb
index 07bc01d6d..cf0845970 100644
--- a/app/helpers/application_helper.rb
+++ b/app/helpers/application_helper.rb
@@ -7,4 +7,31 @@ module ApplicationHelper
return stylesheet_link_tag( _n ).gsub( ' />', '>' )
end
+ # Copied from error_messages_for in active_record_helper.rb
+ def foi_error_messages_for(*params)
+ options = params.last.is_a?(Hash) ? params.pop.symbolize_keys : {}
+ objects = params.collect {|object_name| instance_variable_get("@#{object_name}") }.compact
+ count = objects.inject(0) {|sum, object| sum + object.errors.count }
+ unless count.zero?
+ html = {}
+ [:id, :class].each do |key|
+ if options.include?(key)
+ value = options[key]
+ html[key] = value unless value.blank?
+ else
+ html[key] = 'errorExplanation'
+ end
+ end
+ error_messages = objects.map {|object| object.errors.full_messages.map {|msg| content_tag(:li, msg) } }
+ content_tag(:div,
+ content_tag(:p, 'Please correct the following and try again.') <<
+ content_tag(:ul, error_messages),
+ html
+ )
+ else
+ ''
+ end
+ end
+
+
end
diff --git a/app/views/file_request/create.rhtml b/app/views/file_request/create.rhtml
new file mode 100644
index 000000000..8220705ca
--- /dev/null
+++ b/app/views/file_request/create.rhtml
@@ -0,0 +1,5 @@
+<% @title = "New FOI request" %>
+
+<p>Your Freedom of Information request has been created.
+
+
diff --git a/app/views/file_request/index.rhtml b/app/views/file_request/index.rhtml
index 299a9eac4..ecdcb054d 100644
--- a/app/views/file_request/index.rhtml
+++ b/app/views/file_request/index.rhtml
@@ -1,6 +1,6 @@
<% @title = "New FOI request" %>
-<%= error_messages_for :info_request %>
+<%= foi_error_messages_for :info_request %>
<% form_for(:info_request, @info_request, :url => { :action => :create }, :html => { :id => 'writeForm' } ) do |f| %>
diff --git a/config/environment.rb b/config/environment.rb
index e576d6f7e..462eb4dc0 100644
--- a/config/environment.rb
+++ b/config/environment.rb
@@ -57,4 +57,10 @@ end
# Mime::Type.register "text/richtext", :rtf
# Mime::Type.register "application/x-mobile", :mobile
+# Validation error messages
+ActiveRecord::Errors.default_error_messages[:blank] = "must be filled in"
+
# Include your application configuration below
+
+
+