Ruby on rails 4 Rails 4有很多视图
在我的模型中,Gainloss有许多检查,在以我的表单提交Gainloss模型之前,我需要创建几个检查。 我通常通过创建一个集合,向其中添加json对象,然后提交表单来实现这一点。在Rails中,哪种方法是最好的? 提示:我正在使用formtasticRuby on rails 4 Rails 4有很多视图,ruby-on-rails-4,formtastic,Ruby On Rails 4,Formtastic,在我的模型中,Gainloss有许多检查,在以我的表单提交Gainloss模型之前,我需要创建几个检查。 我通常通过创建一个集合,向其中添加json对象,然后提交表单来实现这一点。在Rails中,哪种方法是最好的? 提示:我正在使用formtastic class Gainloss < ActiveRecord::Base self.table_name = "cashflow" has_many :operations has_many :checks b
class Gainloss < ActiveRecord::Base
self.table_name = "cashflow"
has_many :operations
has_many :checks
belongs_to :account
end
class Check < ActiveRecord::Base
belongs_to :gainloss
end
_form.html.erb
接受\u嵌套的\u属性\u,这可能是您要查找的内容。不,不这样做至少不使用formtastic.nested_attributes_通常是在rails中这样做的。设置它时,您会收到什么错误消息,您的控制器是什么样子的?是否确保通过强参数允许嵌套属性?
<%= semantic_form_for @gainloss do |f| %>
<%= f.inputs do %>
<%= f.input :date, :as => :date_picker, :required => true%>
<%= f.input :gain, :as => :radio, :collection => [['IN',true],['OUT',false]], :label => 'TX Type'%>
<%= f.input :description %>
<%= f.input :account, :collection => Account.all %>
<%= f.input :cash %>
<% end %>
<%= f.semantic_fields_for :checks do |check| %>
<%= check.inputs :date, :bank, :number, :amount, :due, :input_html => { :class => 'form-inline'} %>
<% end%>
<%= f.actions do %>
<%= f.action :submit, :as => :button , :button_html => { :class => "btn btn-primary" }, :label => 'Guardar' %>
<%= f.action :cancel, :as => :link, :button_html => { :class => "btn btn-default" }, :label => 'Cancelar' %>
<% end %>
<% end %>