0

下午好,

我从 Rails 开始,在遵循http://guides.rubyonrails.org/getting_started.html上的指南时,我似乎遇到了障碍。

当我尝试使用 form_for 助手将数组作为参数传递时(如指南第 6.4 节所述),我收到以下错误

显示第 11 行引发的 [MyPath]/app/views/posts/show.html.erb:

[MyPath]/app/models/comment.rb:3:语法错误,意外的keyword_end,?期待 $end

正在呈现的视图的代码是

<p>
  <strong>Title:</strong>
  <%= @post.title %>
</p>

<p>
  <strong>Text:</strong>
  <%= @post.text %>
</p>

<%= form_for([@post, @post.comments.build]) do |f| %>
  <p>
    <%= f.label :commenter %><br />
    <%= f.text_field :commenter %>
  </p>
  <p>
    <%= f.label :body %><br />
    <%= f.text_area :body %>
  </p>
  <p>
    <%= f.submit %>
  </p>
<% end %>

<%= link_to 'Back', posts_path %>
| <%= link_to 'Edit', edit_post_path(@post) %>

这是post模型的样子

class Post < ActiveRecord::Base
  has_many :comments
  validates :title, presence: true,
            length: { minimum: 5 }

end

这就是评论模型的样子

Class Comment < ActiveRecord::Base
  belongs_to :post
end

什么可能导致此问题?“结束”标签似乎正确匹配。

仅供参考,以备不时之需

红宝石-v

ruby 1.9.3p429(2013-05-15 修订版 40747)[x86_64-darwin12.3.0]

导轨-v

导轨 4.0.0

谢谢你的帮助。我不确定是否需要更多信息,但请随时告诉我。

4

1 回答 1

0

错字在这里-

Class Comment <它应该是class Comment <

于 2013-07-07T03:46:20.177 回答