关于ruby教程的form

编程入门 行业动态 更新时间:2024-10-21 23:15:07
关于ruby教程的form_for问题(Issues with form_for following ruby tutorial)

下午好,

我开始使用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 } end

and this is what the comment model looks like

Class Comment < ActiveRecord::Base belongs_to :post end

What 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 <

更多推荐

本文发布于:2023-08-06 21:57:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1456758.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:教程   ruby   form

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!