Ruby on rails Rails应用程序视图中的NoMethodError

Ruby on rails Rails应用程序视图中的NoMethodError,ruby-on-rails,ruby,model-view-controller,partials,Ruby On Rails,Ruby,Model View Controller,Partials,我遵循一个教程,我必须作出一个目录网站排序。由于需要一个用户可以编写评论的页面,我为评论创建了视图和表单。我所采取的步骤是: 1-在app/views/reviews处创建了一个reviews文件夹: 2-在该文件夹中创建一个名为_forms.html.erb的部分,用于审核 <%= simple_form_for(@review) do |f| %> <%= f.error_notification %> <div class="form-inputs

我遵循一个教程,我必须作出一个目录网站排序。由于需要一个用户可以编写评论的页面,我为评论创建了视图和表单。我所采取的步骤是:

1-在app/views/reviews处创建了一个reviews文件夹:

2-在该文件夹中创建一个名为_forms.html.erb的部分,用于审核

 <%= simple_form_for(@review) do |f| %>
  <%= f.error_notification %>

  <div class="form-inputs">
    <%= f.input :content, required: true %>
    <%= f.hidden_field :place_id, required: true, value: @place_id %>
  </div>

  <div class="form-actions">
    <%= f.button :submit %>
  </div>
 <% end %>
My routes.rb文件已获得评论的路线。我得到的错误是:

NoMethodError in Places#show
Showing C:/workinrails/myyelpapp/app/views/reviews/_form.html.erb where line #5 raised:
undefined method `content' for #<Review:0x9200a30>
Trace of template inclusion: app/views/places/show.html.erb

app/views/reviews/_form.html.erb:5:in `block in _app_views_reviews__form_html_erb___988880813_76383660'
app/views/reviews/_form.html.erb:1:in `_app_views_reviews__form_html_erb___988880813_76383660'
app/views/places/show.html.erb:13:in `_app_views_places_show_html_erb__530556826_71913768'
NoMethodError in Places#show
显示C:/workinrails/myyelpap/app/views/reviews/_form.html.erb,其中第5行出现:
未定义的方法“内容”#
模板包含跟踪:app/views/places/show.html.erb
app/views/reviews/_form.html.erb:5:in'block in_app_view_reviews_form_html_erb_988880813_76383660'
app/views/reviews/_-form.html.erb:1:in`_-app\u-views\u-reviews\u-form\u-html\u-erb\u 988880813\u 76383660'
app/views/places/show.html.erb:13:in`_app_views_places_show_html_erb_530556826_71913768'

我可以提供任何代码片段,以便更好地理解

添加一个名为“评论表内容”的新列

bundle exec rails g migration add_content_to_reviews content:string

bundle exec rake db:migrate

您需要在表中添加指定的列名

rails g migration AddColumnNameToTableName列名称:数据类型

然后

rails数据库:迁移

注意:- 您应该知道表单标签与表单标签的区别

表格

您在此处使用表单_,因此您应该仅在已创建的DB列名中指定

表格标签


form_tag您不需要指定所需的列名,您可以使用任何名称,您将在控制器中获得该值的参数

这里您的名称有点混乱。页面与位置。您是否同时拥有PagesController和PlacesController并且忘记在正确的位置添加show action控件我更正了有关问题的信息,谢谢。我有一个页面控制器和一个位置控制器。在我的页面控制器上,只有def home方法,里面没有任何内容。在“显示操作”中的“我的位置”控件中,我有以下内容:@review=review.new审阅表中的列是什么。@rohan您能将字段粘贴到审阅表中吗?
content
context
NoMethodError in Places#show
Showing C:/workinrails/myyelpapp/app/views/reviews/_form.html.erb where line #5 raised:
undefined method `content' for #<Review:0x9200a30>
Trace of template inclusion: app/views/places/show.html.erb

app/views/reviews/_form.html.erb:5:in `block in _app_views_reviews__form_html_erb___988880813_76383660'
app/views/reviews/_form.html.erb:1:in `_app_views_reviews__form_html_erb___988880813_76383660'
app/views/places/show.html.erb:13:in `_app_views_places_show_html_erb__530556826_71913768'
bundle exec rails g migration add_content_to_reviews content:string

bundle exec rake db:migrate