未提交Formtastic /导轨形式(Formtastic / rails forms not s

2019-10-16 14:45发布

我试图用formtastic做一个形式,我可以输入:反对选择:场地和:团队,然后与球员,我能够检查关,选择他们的一个列表中呈现

我已经得到形式设置,以便提交时不保存任何信息,只是重新加载页面它呈现正常不过。

我的代码是在我的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

形成

<%= semantic_form_for :fixture do |f| %>
 <%= f.inputs do %>
  <%= f.input :opposition  %>
  <%= f.input :team, :as => :select, :collection => Team.all %>
  <%= f.input :venue, :as => :check_boxes, :collection => Hash[Venue.all.map{|b| [b.name, b.id]}]%>
  <%= f.input :players, :as => :check_boxes, :collection => Hash[Player.all.map{|b| [b.full_name, b.id]}], :required => true  %>
<% end %>
<%= f.actions do %>
 <%=  f.action :submit, :as => :button %>
 <%=  f.action :cancel, :as => :link %>
<% end %>
<% end %>

所以,当表单提交现在没有通过。 当在web服务器砖没什么期待被提交,但页面只是被重新加载。

它可以插入使用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

Answer 1:

我的猜测是massassignment。 您需要允许导轨通过massassignment更新一些属性。

该行添加到您的灯具型号:

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

这使导轨设置通过这些属性newupdate_attributes的方法。

请参阅安全护栏指南以获取更多信息。



文章来源: Formtastic / rails forms not submitting