有人可以帮我解决这个我一直得到的NoMethodError吗?
undefined method `full_name' for #<Customer:0x007fb3d2c672c0>
这是我的HTML:
<%= form_for(@customer, as: 'customer', url: {action: "create"}) do |f| %>
<%= f.label :full_name, 'Name', :class => 'checkout-label' %>
<%= f.text_field :full_name, :placeholder => 'Name', :class => 'checkout-input', :required => true %>
<% end %>
以下是我的customer_controller.rb中列出的内容:
class CustomerController < ApplicationController
def checkout
@customer = Customer.new
end
def create
@customer = Customer.new(customer_params)
render :confirm
end
def confirm
end
private
def customer_params
params.require(:customer).permit(:full_name, :email, :account_number, :disclaimer)
end
end
这是我的customer.rb:
validates_presence_of :full_name,
:email,
:account_number,
:disclaimer
我在哪里没有定义方法?
答案 0 :(得分:0)
您可能忘记运行迁移以创建first_name
属性。试试这个:
rails g migration add_first_name_to_customers first_name:string
然后迁移您的数据库:
rake db:migrate