I am new to Ruby on Rails and I am having an issue when I am about to submit my form. Everything when well when I was about to create the form(as shown in 1st picture), but as soon as I get to the show path I show nothing of what I input to the form (as shown on 2nd picture).Can somebody eluded where I was wrong?
class TodosController < ApplicationController
def index
@todos= Todo.all
end
def new
end
def show
@todo = Todo.find(params[:id])
end
def create
@todo= Todo.new(todo_params)
@todo.save
redirect_to @todo
end
private
def todo_params
params.require(:todo).permit(:task, :description)
end
end
In my show.html.erb:
<p>
<strong>Task:</strong>
<%= @todo.task %>
</p>
<p>
<strong>Description:</strong>
<%= @todo.description %>
</p>
in my routes.rb:
Rails.application.routes.draw do
get 'welcome/index'
resources :todos
root 'welcome#index'
end
On your form page(todo#new) you need to have an object for those attributes(:task, :description) to be saved to in the database.