Last active
April 20, 2018 11:51
-
-
Save foliwe/ca4b590d87fb975cccc06c25c252af9e to your computer and use it in GitHub Desktop.
Project Managment
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Views/tasks/_task.html.erb | |
<tr> | |
<td><%= task.name%></td> | |
<td> | |
<%= link_to 'Destroy ', [task.project, task], | |
method: :delete, | |
data: { confirm: 'Are you sure?' } %> | |
</td> | |
</tr> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Project < ApplicationRecord | |
has_many :tasks , dependent: :destroy | |
has_many :expenses,dependent: :destroy | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
lass ProjectsController < ApplicationController | |
before_action :find_project ,except: [:index] | |
def index | |
@projects = Project.all | |
end | |
def show | |
@total_expenses = @project.expenses.map(&:cost).sum | |
end | |
private | |
def find_project | |
@project = Project.find(params[:id]) | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
resources :projects do | |
resources :tasks | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
views/project/show.html.erb | |
<%= render @project.tasks %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class TasksController < ApplicationController | |
def create | |
@project = Project.find(params[:project_id]) | |
@task = @project.tasks.create(task_params) | |
redirect_to project_path(@project) | |
end | |
def destroy | |
@project = Project.find(params[:project_id]) | |
@task = @project.tasks.find(params[:id]) | |
@task.destroy | |
redirect_to project_path(@project) | |
end | |
private | |
def task_params | |
params.require(:task).permit(:name) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This loop
<%= render @project.tasks %>
will render all tasksHow do i create another tasks loop for only uncompleted tasks