false
end
+ # Redirects to the request referer if present, redirects to args or call block otherwise.
+ def redirect_to_referer_or(*args, &block)
+ redirect_to :back
+ rescue ::ActionController::RedirectBackError
+ if args.any?
+ redirect_to *args
+ elsif block_given?
+ block.call
+ else
+ raise "#redirect_to_referer_or takes arguments or a block"
+ end
+ end
+
def render_403(options={})
@project = nil
render_error({:message => :notice_not_authorized, :status => 403}.merge(options))
end
# Make sure association callbacks are called
@attachment.container.attachments.delete(@attachment)
- redirect_to :back
- rescue ::ActionController::RedirectBackError
- redirect_to :controller => 'projects', :action => 'show', :id => @project
+ redirect_back_or_default project_path(@project)
end
private
respond_to do |format|
format.html {
flash[:notice] = l(:notice_successful_update)
- redirect_to :back
+ redirect_to_referer_or edit_user_path(@user)
}
format.api { head :ok }
end
format.api { render_validation_errors(@user) }
end
end
- rescue ::ActionController::RedirectBackError
- redirect_to :controller => 'users', :action => 'edit', :id => @user
end
def destroy
end
end
respond_to do |format|
- format.html { redirect_to :back }
+ format.html { redirect_to_referer_or {render :text => 'Watcher added.', :layout => true}}
format.js do
render :update do |page|
page.replace_html 'ajax-modal', :partial => 'watchers/new', :locals => {:watched => @watched}
end
end
end
- rescue ::ActionController::RedirectBackError
- render :text => 'Watcher added.', :layout => true
end
def append
def set_watcher(user, watching)
@watched.set_watcher(user, watching)
respond_to do |format|
- format.html { redirect_to :back }
+ format.html { redirect_to_referer_or {render :text => (watching ? 'Watcher added.' : 'Watcher removed.'), :layout => true}}
format.js do
render(:update) do |page|
c = watcher_css(@watched)
end
end
end
- rescue ::ActionController::RedirectBackError
- render :text => (watching ? 'Watcher added.' : 'Watcher removed.'), :layout => true
end
end