Last active
December 19, 2015 22:59
-
-
Save biographie/6031300 to your computer and use it in GitHub Desktop.
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 index | |
end | |
def show | |
end | |
def new | |
@task = Task.new | |
@new_task.due_date_word = 'Tomorrow' | |
end | |
def create | |
@company = Company.find(params[:company_id]) | |
@task = @company.tasks.create(params[:task]) | |
if @task.save | |
redirect_to "/tasks" | |
else | |
render 'new' | |
end | |
end | |
def edit | |
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
<div class="container"> | |
<div class="content pull-left"> | |
<%= form_for(@task, :url => {:action => "create"}) do |f| %> | |
<%= f.label :description %> | |
<%= f.text_field :description, :class => "input-width bottom-border" %> | |
<%= f.label :task_category_id, "Choose a category" %> | |
<%= f.collection_select(:task_category_id, TaskCategory.all, :id, :task_category) %> | |
<%= f.label :due_date %> | |
<%= f.select :due_date_word, ['Today', 'Tomorrow', 'Next Week']%> | |
<%= f.submit "Add this Task", class: "btn" %> | |
<% end %> | |
</div> | |
</div> |
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
# == Schema Information | |
# | |
# Table name: tasks | |
# | |
# id :integer not null, primary key | |
# title :text | |
# task_category_id :integer | |
# due_date :datetime | |
# description :text | |
# completed_at :datetime | |
# company_id :integer | |
# contact_id :integer | |
# user_id :integer | |
# created_at :datetime not null | |
# updated_at :datetime not null | |
# | |
class Task < ActiveRecord::Base | |
attr_accessible :company_id, :completed_at, :contact_id, :description, :due_date, :task_category_id, :title, :user_id, :due_date_word | |
belongs_to :company | |
belongs_to :task_category | |
belongs_to :contact | |
belongs_to :user | |
before_save :check_due_date_word | |
private | |
def check_due_date_word | |
case @due_date_word | |
when 'Today' then self.due_date = Time.now | |
when 'Tomorrow' then self.due_date = Time.now + 1.day | |
end | |
end |
jimmybaker
commented
Jul 18, 2013
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment