0% found this document useful (0 votes)
9 views1 page

Activity Controller

Uploaded by

Dylan Chaos
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views1 page

Activity Controller

Uploaded by

Dylan Chaos
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

class ActivityController < ApplicationController

def index
@category = Category.find(params[:category_id])
@activities = Activity.where(category_id: params[:category_id], user:
current_user).order('created_at DESC')
end

def show
@activity = Activity.find(params[:activity_id])
@category = Category.find(params[:category_id])
end

def new
@category = Category.find(params[:category_id])
@activity = Activity.new
end

def create
transaction = Activity.new(activity_params)
transaction.category_id = params[:category_id]
transaction.user = current_user
if transaction.valid?
transaction.save
flash[:notice] = 'New transaction created successfully'
else
flash[:alert] = "Transaction could't be created"
end
redirect_to categories_url
end

def activity_params
params.require(:activity).permit(:name, :amount)
end
end

You might also like