Rails 求助!一个很基础的关于 link_to 的问题

joke1943 · 2014年11月11日 · 最后由 joke1943 回复于 2014年11月11日 · 2214 次阅读

今天根据“rails 入门指南”这个网站上的“Rails 入门”篇自己改写了一个,只是换了个名字而已,文件夹 blog 改为 attendance,article 改为 note,articles 改为 notes,其他跟教程完全一样,但是到增加链接的地方出了问题,已经搞了半天,求助! 以下是部分源码

首先是路由: chenxindeMacBook-Air:attendance chenxin$ bin/rake routes Prefix Verb URI Pattern Controller#Action notes GET /notes(.:format) notes#index POST /notes(.:format) notes#create new_note GET /notes/new(.:format) notes#new edit_note GET /notes/:id/edit(.:format) notes#edit note GET /notes/:id(.:format) notes#show PATCH /notes/:id(.:format) notes#update PUT /notes/:id(.:format) notes#update DELETE /notes/:id(.:format) notes#destroy

这是控制器: class NotesController < ApplicationController def index @notes = Note.all end def new end def create @note = Note.new(note_params)

@note.save redirect_to @note end def show @note= Note.find(params[:id]) end

private def note_params params.require(:note).permit(:name,:department,:position,:time, :text,:opinion) end end

这里是页面部分:

请假记录

<%= link_to 'New note’, new_notes_path %><!--这里出错,找不到原因,求助!-->

<% @notes.each do |note| %> <% end %>
请假人 时间
<%= note.name %> <%= note.time %> <%= link_to 'Show', note_path(note) %>

错误信息:

错误就在增加了页面部分的“<%= link_to 'New note’, new_notes_path %>

<h1>请假记录</h1>
<%= link_to 'New note, new_notes_path %><!--这里出错,找不到原因,求助!-->

<table>
  <tr>
    <th>请假人</th>
    <th>时间</th>
  </tr>

  <% @notes.each do |note| %>
    <tr>
      <td><%= note.name %></td>
      <td><%= note.time %></td>
      <td><%= link_to 'Show', note_path(note) %></td>
    </tr>
  <% end %>
</table>

如果楼主好好排版就能发现问题了。

#2 楼 @Rei 十分感谢!我就在文本编辑器里面写的,所以很难看出来,十分感谢!顺便可不可推荐一个 IDE 呢?

#3 楼 @joke1943 我不用 IDE,要推荐就是 https://www.jetbrains.com/ruby/ 了。

我现在用 https://atom.io/ 编辑器。

需要 登录 后方可回复, 如果你还没有账号请 注册新账号