我坚持这个错误,我无法弄清楚什么是错的。
class TicketsController < ApplicationController
def new
end
def create
@tickets = Newticket.new(params[:tickets])
@tickets.save
redirect_to @tickets
end
private
def tickets_params
params.require(tickets).permit(:title, :text)
end
end
答案 0 :(得分:2)
您必须将ticket_params
传递给new
方法
def create
# your code
@tickets = Newticket.new(params[:tickets])
# you should use
@tickets = Ticket.new(ticket_params) #if your model is named Ticket
@tickets = Newticket.new(ticket_params) #if your model is named Newticket
@tickets.save
redirect_to @tickets
end
private
def tickets_params
params.require(:tickets).permit(:title, :text) # if your model is named Ticket
params.require(:newtickets).permit(:title, :text) # if your model is named Newticket
end
end
您创建的方法ticket_params
允许来自:tickets
哈希的params
值,并且您已使用permit
说params[:tickets]
哈希中允许哪些密钥宾语。你放了:title, :text
。问题是您使用的params[:ticket]
没有允许参数。
答案 1 :(得分:0)
@tickets = Newticket.new(params [:tickets])
Newticket.new那个人造成了麻烦。我在生成控制器时定义了该方法错误,我将其称为Newticket,而我应该将其称为票证。
感谢您的投入。