Formtastic / rails表格未提交

我正在尝试使用formtastic制作一个表格,我可以进入:反对选择a:场地和a:团队然后会出现一个我可以检查选择它们的球员列表

我已经设置了表单以便正确呈现,但是在提交时它不会保存任何信息并只是重新加载页面。

我的代码在我的github: https : //github.com/jpknegtel/st_francis

楷模

这涉及以下模型:

播放机

has_many :player_fixtures has_many :fixtures, :through => :player_fixtures 

灯具

  has_many :player_fixtures has_many :players, :through => :player_fixtures 

PlayerFixture

 belongs_to :player belongs_to :fixture 

调节器

 def create @fixture = Fixture.new(params[:fixture]) if @fixture.save flash[:notice] = "Fixture Created" redirect_to(:action =>'list') else flash.now[:error] = "Could not save fixture. Please re-enter information" render('new') end end def new @fixture = Fixture.new end 

形成

     :select, :collection => Team.all %>  :check_boxes, :collection => Hash[Venue.all.map{|b| [b.name, b.id]}]%>  :check_boxes, :collection => Hash[Player.all.map{|b| [b.full_name, b.id]}], :required => true %>    :button %>  :link %>   

因此,当提交表单时,现在没有任何内容通过。 在查看Web brick服务器时,没有提交任何内容,但页面才会重新加载。

可以使用rails控制台插入记录。

编辑:我现在可以在提交时看到这个。

 Started POST "/fixtures/new" for 127.0.0.1 at 2012-04-23 15:00:21 +0100 Processing by FixturesController#new as HTML Parameters: {"utf8"=>"✓", "authenticity_token"=>"Hx4TChWiUdhpZbAfgWUYMWBKao86pZh0tGzwVKy+P80=", "fixture"=> {"opposition"=>"Mid sussex", "team"=>"1", "venue"=>["", "1"], "players"=>["", "1", "3"]}, "button"=>""} Team Load (1.0ms) SELECT `teams`.* FROM `teams` Venue Load (1.0ms) SELECT `venues`.* FROM `venues` Player Load (1.0ms) SELECT `players`.* FROM `players` Rendered fixtures/new.html.erb within layouts/application (173.0ms) Completed 200 OK in 200ms (Views: 163.0ms | ActiveRecord: 36.0ms) [2012-04-23 15:00:21] WARN Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true 

我的猜测是大规模分配。 您需要允许rails通过massassignment更新某些属性。

将此行添加到您的灯具模型中:

 attr_accessible :players_attributes, :opposition, :team_id, :venue_id, :date 

这允许rails通过newupdate_attributes方法设置这些属性。

有关更多信息,请参阅有关安全性的rails指南 。