-1
todos # index에 NoMethodError가 표시되어 그 이유를 알 수 없습니다.Ruby on Rails : NoMethodError in todos # index
<h1>Listing all Todos</h1>
<p>
<%= link_to "Create a Todo", new_todo_path %>
</p>
<table>
<tr>
<th>Name</th>
<th>Description</th>
</tr>
<% @todos.each do |todo| %>
<tr>
<td><%= todo.name %></td>
<td><%= todo.description %></td>
<td><%= link_to 'Edit', edit_todo_path(todo) %></td>
<td><%= link_to 'Show', todo_path(todo) %></td>
<td><%= link_to 'Delete', todo_path(todo), method: :delete, data: {confirm: "Are you sure?"} %></td>
</tr>
<% end %>
</table>
todos_controller.rb : 잘못된 자리에 end
있었다처럼
class TodosController < ApplicationController
before_action :set_todo, only: [:edit, :update, :show, :destroy]
def new
@todo = Todo.new
end
def create
@todo = Todo.new(todo_params)
if @todo.save
flash[:notice] = "Todo was created successfully"
redirect_to todo_path(@todo)
else
render 'new'
end
end
def show
end
def edit
end
def update
if @todo.update(todo_params)
flash[:notice] = "Todo was successfully updated"
redirect_to todo_path(@todo)
else
render 'edit'
end
end
end
def index
@todos = Todo.all
end
def destroy
@todo.destroy
flash[:notice] = "Todo was deleted successfully"
redirect_to todos_path
end
private
def set_todo
@todo = Todo.find(params[:id])
end
def todo_params
params.require(:todo).permit(:name, :description)
end
'todos'컨트롤러를 게시 할 수 있습니까? – Mark
안녕하세요, 저는 방금 todos_controller.rb 코드를 게시했습니다. – pdenlinger
정말 고마워! 나는 아래에 당신의 질문에 대답했다. – Mark