下午好,
我开始使用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 ,? 期待美元结束
正在呈现的视图的代码是
<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) %>这就是帖子模型的样子
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]
rails -v
Rails 4.0.0
谢谢你的帮助。 我不确定是否需要更多信息,但请随时告诉我。
Good afternoon,
I'm starting out with rails and as I'm following the guide at http://guides.rubyonrails.org/getting_started.html I seem to have hit a roadblock.
When I try to use the form_for helper passing an array as a parameter (as explained in section 6.4 of the guide) I get the following error
Showing [MyPath]/app/views/posts/show.html.erb where line #11 raised:
[MyPath]/app/models/comment.rb:3: syntax error, unexpected keyword_end, ? expecting $end
The code of the view that is being rendered is
<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) %>This is what the post model looks like
class Post < ActiveRecord::Base has_many :comments validates :title, presence: true, length: { minimum: 5 } endand this is what the comment model looks like
Class Comment < ActiveRecord::Base belongs_to :post endWhat could be causing this issue? The "End" tags seem to match up properly.
Just for extra info, in case it is necessary
ruby -v
ruby 1.9.3p429 (2013-05-15 revision 40747) [x86_64-darwin12.3.0]
rails -v
Rails 4.0.0
Thanks for any help. I'm not sure if more information is needed but please feel free to let me know.
最满意答案
错字在这里 -
Class Comment <应该是class Comment <
the typo is here -
Class Comment < It should be class Comment <
更多推荐
发布评论