我无法找到为什么我的强参数没有保存在数据库中的原因。我没有使用脚手架来创建模型,而是使用rails g model Customer Name:string Email:string
命令。使用rails console
.
这是我的页面控制器
class PagesController < ApplicationController
def Home
end
def Login
@customer=Customer.new(master)
@customer.save
end
private
def attr @customer=Customer.find(params[:id]) end
def master params.require(:customer).permit(:Name,:Email) end end
我的 customer.rb 文件
class Customer < ActiveRecord::Base
has_many :Products,through: :Order
end
尝试保存新客户时的开发日志。
Started GET "/Login?Customer%5BName%5D=s&Customer%5BEmail%5D=csc" for 127.0.0.1 at 2013-10-31 04:48:49 +0530 Processing by PagesController#Login as HTML Parameters:
{"Customer"=>{"Name"=>"s", "Email"=>"csc"}} (0.1ms) begin transaction SQL (0.5ms)
INSERT INTO "customers" ("created_at", "updated_at") VALUES (?, ?) [["created_at", Wed, 30 Oct 2013 23:18:49 UTC +00:00], ["updated_at", Wed, 30 Oct 2013 23:18:49 UTC +00:00]] (72.4ms) commit transaction Rendered pages/Login.html.erb within layouts/application (0.1ms) Completed 200 OK in 82ms (Views: 5.7ms | ActiveRecord: 73.0ms)
在浏览器中打开页面时出现的错误:
ActionController::ParameterMissing in PagesController#Login
param not found: customer
Extracted source (around line #17):