Skip to content

Instantly share code, notes, and snippets.

View JoeyBy's full-sized avatar

Joey Byrne JoeyBy

  • Vancouver
View GitHub Profile
class TasksController < ApplicationController
#GET /tasks or using tasks_path
def index
@tasks = Task.all
end
#GET /tasks/new or using new_tasks_path
#this is where our new task form will live
def new
<%= form_for @task do |f| %>
<div>
<%= f.label "title *" %>
<%= f.text_field "title" %>
</div>
<div>
<%= f.label "description" %>
<%= f.text_area "description" %>
<section>
<!--creates an <a> tag around the text "new task" and points it to eh new_task_path defined in our routes -->
<%= link_to "new task", new_task_path %>
<!--loops through each of the tasks returned from the database and passed to the view from the tasks_controller index action -->
<% @tasks.each do |task| %>
<!-- for each task put the title in an h3 tag -->
<h3><%= task.title %></h3>
<!-- for each task put the description in a p tag -->
class TasksController < ApplicationController
# GET /tasks tasks_path
# GET / root_path
def index
@tasks = Task.all
end
# GET /tasks/new new_task_path
def new
Rails.application.routes.draw do
resources :tasks
end
class Task < ActiveRecord::Base
validates_presence_of :title, :message => "A title must be entered"
end
class CreateTasks < ActiveRecord::Migration
def change
create_table :tasks do |t|
t.string :title
t.text :description
t.timestamps null: false
end
end
end