diff --git a/app/controllers/groups_controller.rb b/app/controllers/groups_controller.rb index fd36c16..d97ab50 100644 --- a/app/controllers/groups_controller.rb +++ b/app/controllers/groups_controller.rb @@ -47,10 +47,7 @@ def destroy @group = current_user.groups.find(params[:id]) @group.destroy - respond_to do |format| - format.html { redirect_to groups_url, notice: 'group was successfully destroyed.' } - format.json { head :no_content } - end + redirect_back(fallback_location: root_path) end private diff --git a/app/controllers/static_pages_controller.rb b/app/controllers/static_pages_controller.rb index 784a5ae..9dd56ec 100644 --- a/app/controllers/static_pages_controller.rb +++ b/app/controllers/static_pages_controller.rb @@ -3,4 +3,15 @@ class StaticPagesController < ApplicationController def home end + + def external + user = User.find_by(id: current_user.id) + @external_user_transactions = user.transactions.where(group_id: nil).order(created_at: :desc) + @external_total = @external_user_transactions.sum(:amount) + end + + def friends + @users = User.where.not(id: current_user.id) + @expenses = Expense.where.not(user_id: current_user.id) + end end diff --git a/app/controllers/transactions_controller.rb b/app/controllers/transactions_controller.rb index c1f5d90..4fa8aed 100644 --- a/app/controllers/transactions_controller.rb +++ b/app/controllers/transactions_controller.rb @@ -2,8 +2,12 @@ class TransactionsController < ApplicationController before_action :authenticate_user! def index - @transaction = current_user.transactions.all.sort_by(&:created_at).reverse - @total = current_user.transactions.sum(:amount) + @transaction = current_user.transactions.all + @other_transaction = @transaction.where.not(group_id: nil) + @other_transaction_sorted = @other_transaction.sort_by(&:created_at).reverse + + @total = @other_transaction.sum(:amount) + end def new @@ -11,13 +15,14 @@ def new end def create + @transaction = current_user.transactions.new(transaction_params) if @transaction.save if @transaction.group_id.nil? - redirect_to home_external_path, notice: 'Transaction expense was successfully created.' + redirect_to external_path, notice: 'Transaction expense was successfully created.' else @@ -56,11 +61,8 @@ def destroy @transaction = current_user.transactions.find(params[:id]) @transaction.destroy - - respond_to do |format| - format.html { redirect_to transactions_url, notice: 'Transaction was successfully destroyed.' } - format.json { head :no_content } - end + redirect_back(fallback_location: root_path) + end diff --git a/app/views/static_pages/external.html.erb b/app/views/static_pages/external.html.erb new file mode 100644 index 0000000..7e996e6 --- /dev/null +++ b/app/views/static_pages/external.html.erb @@ -0,0 +1,67 @@ +
+
+
+<%= link_to root_path do %> + +<% end %> +
+
+Extra transactions +
+ + +
+ +

most recent

+ +
+ +
+
+
+ total amount +
+ +
+ $ <%= @external_total %> +
+
+
+ +<% @external_user_transactions.each do |t| %> + +
+
+
+ + + +
+
+
+
<%= t.name %>
+

$ <%= t.amount %>

+

<%= t.created_at %>

+ + <%= link_to "edit", edit_transaction_path(t), :class => "btn btn-primary edit_btn" %> + + <%= link_to "delete", transaction_path(t), :class => "btn btn-danger delete_grp_btn", data: {confirm: "Are you sure?"}, :method => :delete %> +
+
+
+
+<% end %> +
+ +
+ + +
+<%= link_to "Add new", new_transaction_path , :class => "btn btn-success new_trans" %> +
+ + + + diff --git a/app/views/static_pages/home.html.erb b/app/views/static_pages/home.html.erb index a6079ac..8c1e771 100644 --- a/app/views/static_pages/home.html.erb +++ b/app/views/static_pages/home.html.erb @@ -21,7 +21,7 @@
  • - <%= link_to "All my External Transactions", "#", :class => "btn" %> + <%= link_to "All my External Transactions", external_path, :class => "btn" %>

  • diff --git a/app/views/transactions/index.html.erb b/app/views/transactions/index.html.erb index 26e344d..2c9361d 100644 --- a/app/views/transactions/index.html.erb +++ b/app/views/transactions/index.html.erb @@ -30,12 +30,13 @@ Transactions
    -<% @transaction.each do |t| %> +<% @other_transaction_sorted.each do |t| %>
    - + +
    diff --git a/config/routes.rb b/config/routes.rb index dd457e6..a1aba4d 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -3,6 +3,8 @@ devise_for :users resources :transactions resources :groups + + get '/external', to: 'static_pages#external' # For details on the DSL available within this file, see https://guides.rubyonrails.org/routing.html end