html - Couldn't find Todo with 'id' -


hello have searched high , low answer problem, going ask here. i'm new programmer trying learn html , ruby. coding simple todo app cannot figure out how fix error:

"couldn't find todo 'id'=#"

todos_controlller.rb

class todoscontroller < applicationcontroller  def index   @todos = todo.all   end  def new   @todo = todo.new end   def edit   @todo = todo.find(params[:id]) end  def create     @todo = todo.create(todo_params)     redirect_to todos_path end  private  def todo_params   params.require(:todo).permit(:item)end   end 

here views

new.html.slim

= form_for (@todo) |f|  p    = f.text_field :item, :placeholder => "add new item"  p    = f.submit 

edit.html.slim

= form_for(@link) |f|  p    = f.text_field :item  p    = f.submit 

index.html.slim

- @todos.each |todo|   ul         li=todo.item   p  = link_to "new", new_todo_path p  = link_to "edit", edit_todo_path(@todos) p  = link_to "delete", '#' 

routes.rb

rails.application.routes.draw root to: "todos#index"  resources :todos end 

edit:

my edit view written now

= form_for(@todo) |f|   p    = f.text_field :item   p    = f.submit 

i going off tutorial http://masteruby.github.io/weekly-rails/2014/03/22/how-to-create-todo-list-app-static-pages.html#.va8t4_ldu3l

apologies if format wrong, first time asking question here.

if @ index.html.slim need pass single value of todo not todos:

// @todos contains collection of todos - @todos.each |todo|   // inside block todo contains single todo   ul     li=todo.item    p     = link_to "new", new_todo_path   p     = link_to "edit", edit_todo_path(todo) #notice it's todo not @todos   p     = link_to "delete", '#' 

this resolve above error have error in your edit.html.slim need fix otherwise it'll give error, in form have use @todo not @link

= form_for @todo |f|   // fields 

also if want show validation errors form in create method should use .save instead of .create, checkout displaying validation errors in views


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

jsf - How to ajax update an item in the footer of a PrimeFaces dataTable? -

django - CSRF verification failed. Request aborted. CSRF cookie not set -