Browse Source

error messages

pull/1/head
Nicolae Claudius 13 years ago
parent
commit
7db19de366
  1. 11
      app/controllers/application_controller.rb
  2. 10
      app/views/errors/_messages.html.erb
  3. 11
      app/views/errors/access_denied.html.erb
  4. 5
      app/views/errors/access_denied.js.rjs

11
app/controllers/application_controller.rb

@ -2,4 +2,15 @@ class ApplicationController < ActionController::Base
before_filter :authenticate_user!
include SentientController
protect_from_forgery
rescue_from CanCan::AccessDenied, ActiveScaffold::ActionNotAllowed do |exception|
flash.now[:error] = exception.message
render :template => 'errors/access_denied', :layout => 'errors'
end
rescue_from ActiveScaffold::ActionNotAllowed do |exception|
flash.now[:error] = I18n.t("action_not_allowed")
render :template => 'errors/access_denied', :layout => 'errors'
end
end

10
app/views/errors/_messages.html.erb

@ -0,0 +1,10 @@
<% for name in [:info, :warning, :error] %>
<% if flash[name] %>
<div class="<%= "#{name}-message message" %>">
<%= h flash[name] %>
<% if request.xhr? %>
<a href="#" onclick="ActiveScaffold.remove(this.parentNode); return false;" title="<%= as_(:close) %>"><%= as_(:close) %></a>
<% end %>
</div>
<% end %>
<% end %>

11
app/views/errors/access_denied.html.erb

@ -0,0 +1,11 @@
<div class="main_container">
<div class="sheet error-sheet">
<% if request.xhr? %>
<br />
<%= render(:partial => 'messages') %>
<br />
<% else %>
<%= link_to 'Back', :back %>
<% end %>
</div>
</div>

5
app/views/errors/access_denied.js.rjs

@ -0,0 +1,5 @@
if controller.class.uses_active_scaffold?
form_selector = "#{element_form_id(:action => params[:action])}"
page << "var action_link = ActiveScaffold.find_action_link('#{form_selector}');"
page << "action_link.update_flash_messages('#{escape_javascript(render(:partial => 'messages').strip)}');"
end
Loading…
Cancel
Save