【发布时间】:2012-04-21 17:37:30
【问题描述】:
我正在尝试使用 formtastic 制作一个表格,在该表格中我可以输入一个 :opposition 选择一个 :venue 和一个 :team ,然后显示一个玩家列表,我可以勾选这些列表来为
我已经设置了表单,因此它可以正确呈现,但是在提交时它不会保存任何信息,只是重新加载页面。
我的代码在我的 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 %>
因此,现在提交表单时,什么都没有传递。当查看网络砖服务器时,没有任何内容被提交,但页面只是被重新加载。
可以使用 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
【问题讨论】:
-
该仓库中没有“semantic_form_for”。你提交了所有最新的东西吗?
-
我刚刚推送了提交。它现在应该在那里,对此感到抱歉。
-
您可以发布您的控制器
new操作的代码吗?你在那里分配@fixture吗? -
尝试使用
semantic_form_for @fixture... -
已放入新控制器,收到以下错误
undefined methodfixtures_path' for #:0x482be00>`
标签: ruby-on-rails has-and-belongs-to-many formtastic