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 | |
#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 |
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
<%= form_for @task do |f| %> | |
<div> | |
<%= f.label "title *" %> | |
<%= f.text_field "title" %> | |
</div> | |
<div> | |
<%= f.label "description" %> | |
<%= f.text_area "description" %> |
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
<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 --> |
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 | |
# GET /tasks tasks_path | |
# GET / root_path | |
def index | |
@tasks = Task.all | |
end | |
# GET /tasks/new new_task_path | |
def new |
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
Rails.application.routes.draw 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
class Task < ActiveRecord::Base | |
validates_presence_of :title, :message => "A title must be entered" | |
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
class CreateTasks < ActiveRecord::Migration | |
def change | |
create_table :tasks do |t| | |
t.string :title | |
t.text :description | |
t.timestamps null: false | |
end | |
end | |
end |