我的应用程序中的表单标签有问题。
我的用户/显示页面上有一个 form_tag。以下代码不会提供任何错误,但它不会写入数据库。据我所知,我需要将@position_game_stat 添加到我的form_tag 中,因为我的表单将数据设为nil。
用户/show.html.erb
<%= form_tag({:controller => "position_game_stats", :action => "create"}, :method => "post") do %>
<%= label_tag :at_bats %><br />
<%= number_field_tag :at_bats %>
<%= submit_tag("submit") %>
<% end %>
position_game_stats 控制器下创建
@position_game_stat = PositionGameStat.new(参数[:position_game_stat])
这是服务器日志
在 2013-06-20 17:55:47 -0500 开始 POST "/position_game_stats" for 127.0.0.1 由 PositionGameStatsController#create 作为 HTML 参数处理:{"utf8"=>"✓", "authenticity_token"=>"C2FJNDfVPILGx05DI2XqRO5wjC79Of7W4SoLvVpnh+ 4=", "user_id"=>"{:value=>1}", "date"=>{"year"=>"2013", "month"=>"6", "day"=>"20 "}, "at_bats"=>"666", "hits"=>"6", "runs"=>"6", "doubles"=>"6", "triples"=>"6", "homeruns "=>"6", "steals"=>"6", "walks"=>"6", "strike_outs"=>"6", "commit"=>"submit"} (0.1ms) 开始事务 SQL (0.5ms) INSERT INTO "position_game_stats" ("at_bats", "created_at", "date", "doubles", "hits", "homeruns", "runs", "steals ", "strike_outs", "triples", "updated_at", "user_id", "walks") 值 (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) [["at_bats", nil], ["created_at", Thu, 20 Jun 2013 22:55:47 UTC +00:00], ["date", nil], ["doubles", nil], ["hits ", nil], ["homeruns", nil], ["runs", nil], ["steals", nil], ["strike_outs", nil], ["triples", nil], ["updated_at", 2013 年 6 月 20 日星期四 22:55:47 UTC +00:00], ["user_id", nil], ["walks",nil]] (163.5ms) 提交事务用户负载 (0.2ms) SELECT "users".* FROM "users" WHERE "users"."id" = 1 LIMIT 1
先谢谢了...