now we have flash messages

Oleg committed Oct 13, 2010
commit ea8ddcc625205294a450ca11a56fbbeabda67394
Showing 6 changed files with 17 additions and 7 deletions
app/controllers/cms_admin/pages_controller.rb +2 -0
@@ @@ -20,6 +20,7 @@ class CmsAdmin::PagesController < CmsAdmin::BaseController
flash[:notice] = 'Page saved'
redirect_to :action => :edit, :id => @cms_page
rescue ActiveRecord::RecordInvalid
+ flash.now[:error] = 'Failed to create page'
render :action => :new
end
@@ @@ -28,6 +29,7 @@ class CmsAdmin::PagesController < CmsAdmin::BaseController
flash[:notice] = 'Page updated'
redirect_to :action => :edit, :id => @cms_page
rescue ActiveRecord::RecordInvalid
+ flash.now[:error] = 'Failed to update page'
render :action => :edit
end
app/views/cms_admin/pages/_form.html.erb +0 -1
@@ @@ -1,4 +1,3 @@
- <%= form.error_message %>
<%= form.text_field :label, :id => 'slugify' %>
<div class='page_form_extras'>
app/views/layouts/cms_admin.html.erb +3 -0
@@ @@ -24,6 +24,9 @@
</div>
</div>
<div class='center_column'>
+ <% flash.each do |type, message| %>
+ <div class='flash <%= type %>'><%= message %></div>
+ <% end %>
<div class='center_column_content'>
<%= yield %>
</div>
comfortable_mexican_sofa/cms_form_builder.rb b/lib/comfortable_mexican_sofa/cms_form_builder.rb +0 -6
@@ @@ -29,12 +29,6 @@ class CmsFormBuilder < ActionView::Helpers::FormBuilder
"<label for=\"#{object_name}_#{field}\">#{label}</label>".html_safe
end
- def error_message(message = nil)
- return if @object.errors.blank?
- message ||= 'Failed to save. Please correct marked fields.'
- "<div class='form_error'>#{message}</div>".html_safe
- end
-
def submit(value, options = {}, &block)
extra_content = @template.capture(&block) if block_given?
cancel_link ||= options[:cancel_url] ? ' or ' + options.delete(:cancel_url) : ''
public/stylesheets/comfortable_mexican_sofa/structure.css +10 -0
@@ @@ -53,6 +53,16 @@ html, body {
}
/* -- Common Elements ---------------------------------------------------- */
+ .flash {
+ text-align: center;
+ line-height: 25px;
+ color: #fff;
+ background-color: #066B12;
+ margin: 0px 2px;
+ }
+ .flash.error {
+ background-color: #9e0b0f;
+ }
.big_button {
float: right;
padding: 6px 10px;
test/functional/cms_admin/pages_controller_test.rb +2 -0
@@ @@ -155,6 +155,7 @@ class CmsAdmin::PagesControllerTest < ActionController::TestCase
assert_equal 3, page.cms_blocks.size
assert_equal ['content content', 'title content', 999], page.cms_blocks.collect{|b| b.content}
assert_template :new
+ assert_equal 'Failed to create page', flash[:error]
end
end
@@ @@ -204,6 +205,7 @@ class CmsAdmin::PagesControllerTest < ActionController::TestCase
assert_response :success
assert_template :edit
assert assigns(:cms_page)
+ assert_equal 'Failed to update page', flash[:error]
end
def test_destroy