任务模型只有一个字段:标题。
我制作了一个表单来添加一个只有一个字段的新任务:标题
但是在create方法中,我们可以看到title是用“test”填充的
但是在查询中,我们可以看到“nil”……有什么想法吗?
谢谢
Started POST "/tasks" for 127.0.0.1 at 2013-01-03 13:16:44 -0500
Processing by TasksController#create as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"iWaK1QX6VCyeUCueLrRNErJEtdm/ZNxg4d3LU0vKjnY=", "task"=>{"title"
=>"test"}, "commit"=>"Add a new task "}
(0.1ms) begin transaction
SQL (0.9ms) INSERT INTO "tasks" ("created_at", "title", "updated_at") VALUES (?, ?, ?) [["created_at", Thu, 03 Jan 2013 18:16:44 UTC +00:00], ["title", nil], ["updated_at", Thu, 03 Jan 2013 18:16:44 UTC +00:00]]
(0.8ms) commit transaction
Redirected to http://0.0.0.0:3000/tasks
Completed 302 Found in 8ms (ActiveRecord: 1.8ms)
这里是创建方法
def create
@task = Task.new(params[:post])
if @task.save
redirect_to tasks_path, :notice => "Task successfully saved"
else
render "new"
end
end
最佳答案
问题是您获取的是 post
而不是 task
@task = Task.new(params[:task])
关于ruby-on-rails - Rails 新形式 -> 无,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14144843/