表格/Rails表单未提交 [英] Formtastic / rails forms not submitting

查看:110
本文介绍了表格/Rails表单未提交的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用formtastic制作一个表单,在该表单中我可以输入:opposition选择一个:venue和:team,然后显示一个球员列表,我可以检查这些球员以选择

I am trying to use formtastic to make a form where I can enter an :opposition choose a :venue and a :team and then be presented with a list of players that I am able to check off to select them for the

我已经设置好表格,因此它可以正确呈现,但是在提交时它不会保存任何信息,只会重新加载页面.

I have got the form set up so it renders correctly however when submitted it does not save any information and just reloads the page.

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

My code is at my github here: 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 Brick服务器时,什么都没有提交,但是页面只是重新加载了.

So when the form is submitted now nothing is passed. When looking at the web brick server nothing gets submitted but the page just gets reloaded.

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

It is possible to insert the records using rails console.

提交后,我现在可以看到它.

I can now see this when submitted.

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更新某些属性.

My guess is massassignment. You need to allow rails to update some attributes via massassignment.

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

Add this line to your fixtures model:

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

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

This allows rails to set these attributes via new and update_attributes methods.

有关更多信息,请参见有关安全性的导轨指南.

See the rails guide on security for more information.

这篇关于表格/Rails表单未提交的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆