From 116b1c4ed953046359925e605743c2a0e2cb9d32 Mon Sep 17 00:00:00 2001 From: Benjamin Meichsner Date: Tue, 4 Aug 2009 13:05:37 +0200 Subject: [PATCH] Fixed broken link on startpage for non ordergroup members. --- app/controllers/home_controller.rb | 52 +++++++++++++++++------------- 1 file changed, 29 insertions(+), 23 deletions(-) diff --git a/app/controllers/home_controller.rb b/app/controllers/home_controller.rb index 518c296e..4beb7ef9 100644 --- a/app/controllers/home_controller.rb +++ b/app/controllers/home_controller.rb @@ -35,39 +35,45 @@ class HomeController < ApplicationController def ordergroup @user = @current_user @ordergroup = @user.ordergroup - @ordergroup_column_names = ["Description", "Actual Size", "Balance", "Updated"] - @ordergroup_columns = ["description", "account_balance", "account_updated"] - #listing the financial transactions with ajax... + unless @ordergroup.nil? + @ordergroup_column_names = ["Description", "Actual Size", "Balance", "Updated"] + @ordergroup_columns = ["description", "account_balance", "account_updated"] - if params['sort'] - sort = case params['sort'] - when "date" then "created_on" - when "note" then "note" - when "amount" then "amount" - when "date_reverse" then "created_on DESC" - when "note_reverse" then "note DESC" - when "amount_reverse" then "amount DESC" - end + #listing the financial transactions with ajax... + + if params['sort'] + sort = case params['sort'] + when "date" then "created_on" + when "note" then "note" + when "amount" then "amount" + when "date_reverse" then "created_on DESC" + when "note_reverse" then "note DESC" + when "amount_reverse" then "amount DESC" + end else sort = "created_on DESC" end - # or if somebody uses the search field: - conditions = ["note LIKE ?", "%#{params[:query]}%"] unless params[:query].nil? + # or if somebody uses the search field: + conditions = ["note LIKE ?", "%#{params[:query]}%"] unless params[:query].nil? - @total = @ordergroup.financial_transactions.count(:conditions => conditions) - @financial_transactions = @ordergroup.financial_transactions.paginate(:page => params[:page], - :per_page => 10, - :conditions => conditions, - :order => sort) - respond_to do |format| - format.html # myOrdergroup.haml - format.js { render :partial => "finance/transactions/list" } + @total = @ordergroup.financial_transactions.count(:conditions => conditions) + @financial_transactions = @ordergroup.financial_transactions.paginate(:page => params[:page], + :per_page => 10, + :conditions => conditions, + :order => sort) + respond_to do |format| + format.html # myOrdergroup.haml + format.js { render :partial => "finance/transactions/list" } + end + else + flash[:error] = "Leider bist Du kein Mitglied einer Bestellgruppe" + redirect_to root_path end end - # cancel personal memberships direct from the myProfile-page + # cancel personal memberships direct from the myProfile-page def cancel_membership membership = Membership.find(params[:membership_id]) if membership.user == current_user