Ruby on rails 如何组合a<;部门>;“带栏杆”;链接到;?
我正在创建一个“待办网站”。用户可以登录并生成任务和注释。这些任务做得很好,但出于某种原因,我在笔记方面遇到了一些问题。我不使用任何部分作为注释。如果我在我的index.html.erb上使用此选项,就像我在任务中所做的那样:Ruby on rails 如何组合a<;部门>;“带栏杆”;链接到;?,ruby-on-rails,ruby,Ruby On Rails,Ruby,我正在创建一个“待办网站”。用户可以登录并生成任务和注释。这些任务做得很好,但出于某种原因,我在笔记方面遇到了一些问题。我不使用任何部分作为注释。如果我在我的index.html.erb上使用此选项,就像我在任务中所做的那样: <div class="notes"> <%= link_to 'New Note', new_note_path %> <div class="note"> <div> <%= link_to n
<div class="notes">
<%= link_to 'New Note', new_note_path %>
<div class="note">
<div>
<%= link_to note_path(note) do %>
<%= note.content %>
<%= link_to 'X', note, :class => 'task-destroy', method: :delete, data: {confirm: 'Are you sure?'} %>
<% end %>
</div>
<div>
<%= link_to edit_note_path(note) do %>
<%= time_ago_in_words(note.updated_at) %> ago
<% end %>
</div>
</div>
</div>
“任务销毁”,方法::删除,数据:{确认:'确定吗?}%>
以前
我得到:
“NotesController#索引中的名称错误”-“未定义的局部变量或
#……的方法“注释”
notes\u controller.rb
class NotesController < ApplicationController
before_action :logged_in_user
before_action :set_note, only: [:show, :edit, :update, :destroy]
def index
@notes = current_user.notes
end
def show
end
def new
@note = Note.new
end
def edit
end
def create
@note = current_user.notes.new(note_params)
if @note.save
flash[:success] = "You successfully created a Note!"
redirect_to notes_path
else
render 'new_note_path'
end
end
def update
@note.update(note_params)
if @note.save
flash[:success] = "You successfully updated a Note!"
redirect_to notes_path
else
render 'edit_note_path'
end
end
def destroy
@note.destroy
flash[:success] = "You successfully deleted a Note!"
redirect_to notes_path
end
private
def set_note
@note = Note.find(params[:id])
end
def note_params
params.require(:note).permit(:content)
end
end
class NotesController
问题:我的控制器上的实例变量有什么问题,我如何使其工作?您的
index.html.erb
视图无法访问注意变量
以下方法中的实例变量是传递给视图的唯一变量:
def index
@notes = current_user.notes
end
你可能需要做一些事情,比如
<% @notes.each do |n| >
<%= link_to(n) >
<% end >
您的index.html.erb
视图无权访问注释
变量
以下方法中的实例变量是传递给视图的唯一变量:
def index
@notes = current_user.notes
end
你可能需要做一些事情,比如
<% @notes.each do |n| >
<%= link_to(n) >
<% end >
在
之前添加循环,以循环索引操作中存储在@notes
中的注释列表
Html应如下所示:
<% @notes.each do |note| %>
<div class="note">
<div>
<%= link_to note_path(note) do %>
<%= note.content %>
<%= link_to 'X', note, :class => 'task-destroy', method: :delete, data: {confirm: 'Are you sure?'} %>
<% end %>
</div>
<div>
<%= link_to edit_note_path(note) do %>
<%= time_ago_in_words(note.updated_at) %> ago
<% end %>
</div>
</div>
</div>
<% end %>
“任务销毁”,方法::删除,数据:{确认:'确定吗?}%>
以前
在
之前添加循环,以循环索引操作中存储在@notes
中的注释列表
Html应如下所示:
<% @notes.each do |note| %>
<div class="note">
<div>
<%= link_to note_path(note) do %>
<%= note.content %>
<%= link_to 'X', note, :class => 'task-destroy', method: :delete, data: {confirm: 'Are you sure?'} %>
<% end %>
</div>
<div>
<%= link_to edit_note_path(note) do %>
<%= time_ago_in_words(note.updated_at) %> ago
<% end %>
</div>
</div>
</div>
<% end %>
“任务销毁”,方法::删除,数据:{确认:'确定吗?}%>
以前
您在哪一行收到该错误?确切的错误消息是什么?什么对象不响应注意
?您在哪一行得到该错误?确切的错误消息是什么?什么对象不响应注意
?