伙计们..。我正在学习Rail上的Ruby,但是我不知道这个页面上发生了什么,这是我的错误:
显示/home/ubuntu/workspace/simplecodecasts_saas/app/views/contacts/new.html.erb #7行的Contacts#new中的NoMethodError :未定义的方法#
这是我的new.html.erb
<div class="row">
<div class="col-md-4 col-md-offset-4">
<div class="well">
<%= form_for @contact do |f| %>
<div class="form-group">
<%= f.label :name %>
<%= f.text_field :name, class: 'form-control' %>
</div>
<div class="form-group">
<%= f.label :email %>
<%= f.email_field :email, class: 'form-control' %>
</div>
<div class="form-group">
<%= f.label :comments %>
<%= f.text_area :comments, class: 'form-control' %>
</div>
<%= f.submit 'Submit', class: 'btn btn-default' %>
<% end %>
</div>
</div>
</div>这是我的路线
Rails.application.routes.draw do
resources :contacts
get '/about' => 'pages#about'
root 'pages#home'还有我的contacts_controller.rb
class ContactsController < ApplicationController
def new
@contact = Contact.new
end
def create
end
end出什么问题了?
全误差屏幕屏幕
发布于 2015-11-01 17:59:42
根据您的图像错误,联系人中没有name字段,请重新运行迁移或添加这些字段。
#< contacts id: nil>意味着联系人只有id,所以我想您所做的是在运行这个迁移之后添加这些字段,它不会调用数据库!
请为这些字段重新创建迁移,并从原始文件中删除它们,所有这些都应该可以。
不要在运行迁移文件后向迁移文件中添加任何东西--这会在从头部署这个应用程序时造成很大的问题。
https://stackoverflow.com/questions/33465183
复制相似问题