在 Rails 部分访问通过的本地人时遇到问题
Trouble accessing passed locals in Rails partial
这是我父视图中的相关区域:
<h1>New Bet</h1>
<%= form_for :bet, url: bets_path do |f| %>
<% if @bet.errors.any? %>
<div id="error_explanation">
<h2>
<%= pluralize(@bet.errors.count, "error") %> prohibited
this bet from being saved:
</h2>
<ul>
<% @bet.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
<p>
<%= f.label :odds %><br>
<%= f.text_field :odds %>
</p>
<p>
<%= f.label :time_completed %><br>
<%= f.datetime_select(:time_completed, default: 2.days.from_now) %>
</p>
<div class='picks' id='bet-<%= @bet.id %>'>
<h2>Picks</h2>
<% f.fields_for :picks do |pick_form| %>
<%= render :partial => '/picks/new', :locals => { :f => pick_form, :pick => pick_form.object } %>
<% end %>
<div id='new-picks'>
</div>
<p><a href='#' class='pick-add'>add a pick</a></p>
</div>
<p>
<%= f.submit %>
</p>
<% end %>
<%= link_to 'Back', bets_path %>
以及对应的子(部分)视图:
<%#
locals:
f - form context
pick - Pick to be displayed
%>
<div class='pick' id='<%= pick.id %>'>
<h3>Pick</h3>
<%= f.hidden_field :id %>
<p>
<%= f.label :sport %><br>
<%= f.text_field :sport %>
</p>
<p>
<%= f.label :team %><br>
<%= f.text_field :team %>
</p>
<p>
<%= f.label :league %><br>
<%= f.text_field :league %>
</p>
<p><a href='#' class='pick-remove'>Remove the pick above</a></p>
</div>
当我尝试打开使用父视图的路由时出现此错误...
undefined method `id' for nil:NilClass
从局部视图中突出显示的行是 <div class='pick' id='<%= pick.id %>'>
。
我是不是漏掉了一些明显的东西?
编辑:
感谢@BroiSatse,我更新了我的控制器以包含 @bet.picks.build
,它现在看起来像这样:
def new
@bet = Bet.new
@bet.picks.build
end
但是当我打开视图时,我得到了一个 undefined method 'val' for #<Arel::Nodes::BindParam:0x007f9ab7acfbf8
在线添加,这是一个堆栈跟踪:
activerecord (4.2.0) lib/active_record/relation.rb:572:in `block (2 levels) in where_values_hash'
activerecord (4.2.0) lib/active_record/relation.rb:568:in `fetch'
activerecord (4.2.0) lib/active_record/relation.rb:568:in `block in where_values_hash'
activerecord (4.2.0) lib/active_record/relation.rb:566:in `map'
activerecord (4.2.0) lib/active_record/relation.rb:566:in `where_values_hash'
activerecord (4.2.0) lib/active_record/relation.rb:579:in `scope_for_create'
activerecord (4.2.0) lib/active_record/associations/collection_association.rb:503:in `create_scope'
activerecord (4.2.0) lib/active_record/associations/association.rb:168:in `initialize_attributes'
activerecord (4.2.0) lib/active_record/associations/association.rb:248:in `block in build_record'
activerecord (4.2.0) lib/active_record/core.rb:282:in `initialize'
activerecord (4.2.0) lib/active_record/inheritance.rb:61:in `new'
activerecord (4.2.0) lib/active_record/inheritance.rb:61:in `new'
activerecord (4.2.0) lib/active_record/reflection.rb:131:in `build_association'
activerecord (4.2.0) lib/active_record/associations/association.rb:247:in `build_record'
activerecord (4.2.0) lib/active_record/associations/collection_association.rb:136:in `build'
activerecord (4.2.0) lib/active_record/associations/collection_proxy.rb:254:in `build'
app/controllers/bets_controller.rb:9:in `new'
actionpack (4.2.0) lib/action_controller/metal/implicit_render.rb:4:in `send_action'
actionpack (4.2.0) lib/abstract_controller/base.rb:198:in `process_action'
actionpack (4.2.0) lib/action_controller/metal/rendering.rb:10:in `process_action'
actionpack (4.2.0) lib/abstract_controller/callbacks.rb:20:in `block in process_action'
activesupport (4.2.0) lib/active_support/callbacks.rb:117:in `call'
activesupport (4.2.0) lib/active_support/callbacks.rb:117:in `call'
activesupport (4.2.0) lib/active_support/callbacks.rb:234:in `block in halting'
activesupport (4.2.0) lib/active_support/callbacks.rb:234:in `call'
activesupport (4.2.0) lib/active_support/callbacks.rb:234:in `block in halting'
activesupport (4.2.0) lib/active_support/callbacks.rb:169:in `call'
activesupport (4.2.0) lib/active_support/callbacks.rb:169:in `block in halting'
activesupport (4.2.0) lib/active_support/callbacks.rb:169:in `call'
activesupport (4.2.0) lib/active_support/callbacks.rb:169:in `block in halting'
activesupport (4.2.0) lib/active_support/callbacks.rb:234:in `call'
activesupport (4.2.0) lib/active_support/callbacks.rb:234:in `block in halting'
activesupport (4.2.0) lib/active_support/callbacks.rb:169:in `call'
activesupport (4.2.0) lib/active_support/callbacks.rb:169:in `block in halting'
activesupport (4.2.0) lib/active_support/callbacks.rb:92:in `call'
activesupport (4.2.0) lib/active_support/callbacks.rb:92:in `_run_callbacks'
activesupport (4.2.0) lib/active_support/callbacks.rb:734:in `_run_process_action_callbacks'
activesupport (4.2.0) lib/active_support/callbacks.rb:81:in `run_callbacks'
actionpack (4.2.0) lib/abstract_controller/callbacks.rb:19:in `process_action'
actionpack (4.2.0) lib/action_controller/metal/rescue.rb:29:in `process_action'
actionpack (4.2.0) lib/action_controller/metal/instrumentation.rb:31:in `block in process_action'
activesupport (4.2.0) lib/active_support/notifications.rb:164:in `block in instrument'
activesupport (4.2.0) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
activesupport (4.2.0) lib/active_support/notifications.rb:164:in `instrument'
actionpack (4.2.0) lib/action_controller/metal/instrumentation.rb:30:in `process_action'
actionpack (4.2.0) lib/action_controller/metal/params_wrapper.rb:250:in `process_action'
activerecord (4.2.0) lib/active_record/railties/controller_runtime.rb:18:in `process_action'
actionpack (4.2.0) lib/abstract_controller/base.rb:137:in `process'
actionview (4.2.0) lib/action_view/rendering.rb:30:in `process'
actionpack (4.2.0) lib/action_controller/metal.rb:195:in `dispatch'
actionpack (4.2.0) lib/action_controller/metal/rack_delegation.rb:13:in `dispatch'
actionpack (4.2.0) lib/action_controller/metal.rb:236:in `block in action'
actionpack (4.2.0) lib/action_dispatch/routing/route_set.rb:73:in `call'
actionpack (4.2.0) lib/action_dispatch/routing/route_set.rb:73:in `dispatch'
actionpack (4.2.0) lib/action_dispatch/routing/route_set.rb:42:in `serve'
actionpack (4.2.0) lib/action_dispatch/journey/router.rb:43:in `block in serve'
actionpack (4.2.0) lib/action_dispatch/journey/router.rb:30:in `each'
actionpack (4.2.0) lib/action_dispatch/journey/router.rb:30:in `serve'
actionpack (4.2.0) lib/action_dispatch/routing/route_set.rb:802:in `call'
warden (1.2.3) lib/warden/manager.rb:35:in `block in call'
warden (1.2.3) lib/warden/manager.rb:34:in `catch'
warden (1.2.3) lib/warden/manager.rb:34:in `call'
rack (1.6.0) lib/rack/etag.rb:24:in `call'
rack (1.6.0) lib/rack/conditionalget.rb:25:in `call'
rack (1.6.0) lib/rack/head.rb:13:in `call'
actionpack (4.2.0) lib/action_dispatch/middleware/params_parser.rb:27:in `call'
actionpack (4.2.0) lib/action_dispatch/middleware/flash.rb:260:in `call'
rack (1.6.0) lib/rack/session/abstract/id.rb:225:in `context'
rack (1.6.0) lib/rack/session/abstract/id.rb:220:in `call'
actionpack (4.2.0) lib/action_dispatch/middleware/cookies.rb:560:in `call'
activerecord (4.2.0) lib/active_record/query_cache.rb:36:in `call'
activerecord (4.2.0) lib/active_record/connection_adapters/abstract/connection_pool.rb:647:in `call'
activerecord (4.2.0) lib/active_record/migration.rb:378:in `call'
actionpack (4.2.0) lib/action_dispatch/middleware/callbacks.rb:29:in `block in call'
activesupport (4.2.0) lib/active_support/callbacks.rb:88:in `call'
activesupport (4.2.0) lib/active_support/callbacks.rb:88:in `_run_callbacks'
activesupport (4.2.0) lib/active_support/callbacks.rb:734:in `_run_call_callbacks'
activesupport (4.2.0) lib/active_support/callbacks.rb:81:in `run_callbacks'
actionpack (4.2.0) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
actionpack (4.2.0) lib/action_dispatch/middleware/reloader.rb:73:in `call'
actionpack (4.2.0) lib/action_dispatch/middleware/remote_ip.rb:78:in `call'
web-console (2.0.0) lib/action_dispatch/debug_exceptions.rb:18:in `middleware_call'
web-console (2.0.0) lib/action_dispatch/debug_exceptions.rb:13:in `call'
actionpack (4.2.0) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
railties (4.2.0) lib/rails/rack/logger.rb:38:in `call_app'
railties (4.2.0) lib/rails/rack/logger.rb:20:in `block in call'
activesupport (4.2.0) lib/active_support/tagged_logging.rb:68:in `block in tagged'
activesupport (4.2.0) lib/active_support/tagged_logging.rb:26:in `tagged'
activesupport (4.2.0) lib/active_support/tagged_logging.rb:68:in `tagged'
railties (4.2.0) lib/rails/rack/logger.rb:20:in `call'
actionpack (4.2.0) lib/action_dispatch/middleware/request_id.rb:21:in `call'
rack (1.6.0) lib/rack/methodoverride.rb:22:in `call'
rack (1.6.0) lib/rack/runtime.rb:18:in `call'
activesupport (4.2.0) lib/active_support/cache/strategy/local_cache_middleware.rb:28:in `call'
rack (1.6.0) lib/rack/lock.rb:17:in `call'
actionpack (4.2.0) lib/action_dispatch/middleware/static.rb:113:in `call'
rack (1.6.0) lib/rack/sendfile.rb:113:in `call'
railties (4.2.0) lib/rails/engine.rb:518:in `call'
railties (4.2.0) lib/rails/application.rb:164:in `call'
rack (1.6.0) lib/rack/lock.rb:17:in `call'
rack (1.6.0) lib/rack/content_length.rb:15:in `call'
rack (1.6.0) lib/rack/handler/webrick.rb:89:in `service'
/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/webrick/httpserver.rb:138:in `service'
/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/webrick/httpserver.rb:94:in `run'
/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/webrick/server.rb:295:in `block in start_thread'
我的赌注模型:
class Bet < ActiveRecord::Base
has_many :picks, dependent: :destroy
accepts_nested_attributes_for :picks
validates :odds, presence: true, numericality: true # { only_integer: true }
validates :time_completed, presence: true
end
我的选择型号:
class Pick < ActiveRecord::Base
belongs_to :bet
validates :team, presence: true #, length: { minimum: 1 }
validates :sport, presence: true, inclusion: { :in => ['Basketbal', 'Ice Hockey'] }
validates :league, presence: true, inclusion: { :in => %w( NBA NHL ) }
end
您是否在控制器中定义了 @bet
变量?如果是这样,请将您的 form_for
更改为 form_for @bet
。您的投注模型中还需要 accepts_nested_attributes_for :picks
。
请尝试一下,希望对您有所帮助
<% f.fields_for :picks do |pick_form| %>
<%= render :partial => '/picks/new', :f => pick_form %>
<% end %>
这是我父视图中的相关区域:
<h1>New Bet</h1>
<%= form_for :bet, url: bets_path do |f| %>
<% if @bet.errors.any? %>
<div id="error_explanation">
<h2>
<%= pluralize(@bet.errors.count, "error") %> prohibited
this bet from being saved:
</h2>
<ul>
<% @bet.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
<p>
<%= f.label :odds %><br>
<%= f.text_field :odds %>
</p>
<p>
<%= f.label :time_completed %><br>
<%= f.datetime_select(:time_completed, default: 2.days.from_now) %>
</p>
<div class='picks' id='bet-<%= @bet.id %>'>
<h2>Picks</h2>
<% f.fields_for :picks do |pick_form| %>
<%= render :partial => '/picks/new', :locals => { :f => pick_form, :pick => pick_form.object } %>
<% end %>
<div id='new-picks'>
</div>
<p><a href='#' class='pick-add'>add a pick</a></p>
</div>
<p>
<%= f.submit %>
</p>
<% end %>
<%= link_to 'Back', bets_path %>
以及对应的子(部分)视图:
<%#
locals:
f - form context
pick - Pick to be displayed
%>
<div class='pick' id='<%= pick.id %>'>
<h3>Pick</h3>
<%= f.hidden_field :id %>
<p>
<%= f.label :sport %><br>
<%= f.text_field :sport %>
</p>
<p>
<%= f.label :team %><br>
<%= f.text_field :team %>
</p>
<p>
<%= f.label :league %><br>
<%= f.text_field :league %>
</p>
<p><a href='#' class='pick-remove'>Remove the pick above</a></p>
</div>
当我尝试打开使用父视图的路由时出现此错误...
undefined method `id' for nil:NilClass
从局部视图中突出显示的行是 <div class='pick' id='<%= pick.id %>'>
。
我是不是漏掉了一些明显的东西?
编辑:
感谢@BroiSatse,我更新了我的控制器以包含 @bet.picks.build
,它现在看起来像这样:
def new
@bet = Bet.new
@bet.picks.build
end
但是当我打开视图时,我得到了一个 undefined method 'val' for #<Arel::Nodes::BindParam:0x007f9ab7acfbf8
在线添加,这是一个堆栈跟踪:
activerecord (4.2.0) lib/active_record/relation.rb:572:in `block (2 levels) in where_values_hash'
activerecord (4.2.0) lib/active_record/relation.rb:568:in `fetch'
activerecord (4.2.0) lib/active_record/relation.rb:568:in `block in where_values_hash'
activerecord (4.2.0) lib/active_record/relation.rb:566:in `map'
activerecord (4.2.0) lib/active_record/relation.rb:566:in `where_values_hash'
activerecord (4.2.0) lib/active_record/relation.rb:579:in `scope_for_create'
activerecord (4.2.0) lib/active_record/associations/collection_association.rb:503:in `create_scope'
activerecord (4.2.0) lib/active_record/associations/association.rb:168:in `initialize_attributes'
activerecord (4.2.0) lib/active_record/associations/association.rb:248:in `block in build_record'
activerecord (4.2.0) lib/active_record/core.rb:282:in `initialize'
activerecord (4.2.0) lib/active_record/inheritance.rb:61:in `new'
activerecord (4.2.0) lib/active_record/inheritance.rb:61:in `new'
activerecord (4.2.0) lib/active_record/reflection.rb:131:in `build_association'
activerecord (4.2.0) lib/active_record/associations/association.rb:247:in `build_record'
activerecord (4.2.0) lib/active_record/associations/collection_association.rb:136:in `build'
activerecord (4.2.0) lib/active_record/associations/collection_proxy.rb:254:in `build'
app/controllers/bets_controller.rb:9:in `new'
actionpack (4.2.0) lib/action_controller/metal/implicit_render.rb:4:in `send_action'
actionpack (4.2.0) lib/abstract_controller/base.rb:198:in `process_action'
actionpack (4.2.0) lib/action_controller/metal/rendering.rb:10:in `process_action'
actionpack (4.2.0) lib/abstract_controller/callbacks.rb:20:in `block in process_action'
activesupport (4.2.0) lib/active_support/callbacks.rb:117:in `call'
activesupport (4.2.0) lib/active_support/callbacks.rb:117:in `call'
activesupport (4.2.0) lib/active_support/callbacks.rb:234:in `block in halting'
activesupport (4.2.0) lib/active_support/callbacks.rb:234:in `call'
activesupport (4.2.0) lib/active_support/callbacks.rb:234:in `block in halting'
activesupport (4.2.0) lib/active_support/callbacks.rb:169:in `call'
activesupport (4.2.0) lib/active_support/callbacks.rb:169:in `block in halting'
activesupport (4.2.0) lib/active_support/callbacks.rb:169:in `call'
activesupport (4.2.0) lib/active_support/callbacks.rb:169:in `block in halting'
activesupport (4.2.0) lib/active_support/callbacks.rb:234:in `call'
activesupport (4.2.0) lib/active_support/callbacks.rb:234:in `block in halting'
activesupport (4.2.0) lib/active_support/callbacks.rb:169:in `call'
activesupport (4.2.0) lib/active_support/callbacks.rb:169:in `block in halting'
activesupport (4.2.0) lib/active_support/callbacks.rb:92:in `call'
activesupport (4.2.0) lib/active_support/callbacks.rb:92:in `_run_callbacks'
activesupport (4.2.0) lib/active_support/callbacks.rb:734:in `_run_process_action_callbacks'
activesupport (4.2.0) lib/active_support/callbacks.rb:81:in `run_callbacks'
actionpack (4.2.0) lib/abstract_controller/callbacks.rb:19:in `process_action'
actionpack (4.2.0) lib/action_controller/metal/rescue.rb:29:in `process_action'
actionpack (4.2.0) lib/action_controller/metal/instrumentation.rb:31:in `block in process_action'
activesupport (4.2.0) lib/active_support/notifications.rb:164:in `block in instrument'
activesupport (4.2.0) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
activesupport (4.2.0) lib/active_support/notifications.rb:164:in `instrument'
actionpack (4.2.0) lib/action_controller/metal/instrumentation.rb:30:in `process_action'
actionpack (4.2.0) lib/action_controller/metal/params_wrapper.rb:250:in `process_action'
activerecord (4.2.0) lib/active_record/railties/controller_runtime.rb:18:in `process_action'
actionpack (4.2.0) lib/abstract_controller/base.rb:137:in `process'
actionview (4.2.0) lib/action_view/rendering.rb:30:in `process'
actionpack (4.2.0) lib/action_controller/metal.rb:195:in `dispatch'
actionpack (4.2.0) lib/action_controller/metal/rack_delegation.rb:13:in `dispatch'
actionpack (4.2.0) lib/action_controller/metal.rb:236:in `block in action'
actionpack (4.2.0) lib/action_dispatch/routing/route_set.rb:73:in `call'
actionpack (4.2.0) lib/action_dispatch/routing/route_set.rb:73:in `dispatch'
actionpack (4.2.0) lib/action_dispatch/routing/route_set.rb:42:in `serve'
actionpack (4.2.0) lib/action_dispatch/journey/router.rb:43:in `block in serve'
actionpack (4.2.0) lib/action_dispatch/journey/router.rb:30:in `each'
actionpack (4.2.0) lib/action_dispatch/journey/router.rb:30:in `serve'
actionpack (4.2.0) lib/action_dispatch/routing/route_set.rb:802:in `call'
warden (1.2.3) lib/warden/manager.rb:35:in `block in call'
warden (1.2.3) lib/warden/manager.rb:34:in `catch'
warden (1.2.3) lib/warden/manager.rb:34:in `call'
rack (1.6.0) lib/rack/etag.rb:24:in `call'
rack (1.6.0) lib/rack/conditionalget.rb:25:in `call'
rack (1.6.0) lib/rack/head.rb:13:in `call'
actionpack (4.2.0) lib/action_dispatch/middleware/params_parser.rb:27:in `call'
actionpack (4.2.0) lib/action_dispatch/middleware/flash.rb:260:in `call'
rack (1.6.0) lib/rack/session/abstract/id.rb:225:in `context'
rack (1.6.0) lib/rack/session/abstract/id.rb:220:in `call'
actionpack (4.2.0) lib/action_dispatch/middleware/cookies.rb:560:in `call'
activerecord (4.2.0) lib/active_record/query_cache.rb:36:in `call'
activerecord (4.2.0) lib/active_record/connection_adapters/abstract/connection_pool.rb:647:in `call'
activerecord (4.2.0) lib/active_record/migration.rb:378:in `call'
actionpack (4.2.0) lib/action_dispatch/middleware/callbacks.rb:29:in `block in call'
activesupport (4.2.0) lib/active_support/callbacks.rb:88:in `call'
activesupport (4.2.0) lib/active_support/callbacks.rb:88:in `_run_callbacks'
activesupport (4.2.0) lib/active_support/callbacks.rb:734:in `_run_call_callbacks'
activesupport (4.2.0) lib/active_support/callbacks.rb:81:in `run_callbacks'
actionpack (4.2.0) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
actionpack (4.2.0) lib/action_dispatch/middleware/reloader.rb:73:in `call'
actionpack (4.2.0) lib/action_dispatch/middleware/remote_ip.rb:78:in `call'
web-console (2.0.0) lib/action_dispatch/debug_exceptions.rb:18:in `middleware_call'
web-console (2.0.0) lib/action_dispatch/debug_exceptions.rb:13:in `call'
actionpack (4.2.0) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
railties (4.2.0) lib/rails/rack/logger.rb:38:in `call_app'
railties (4.2.0) lib/rails/rack/logger.rb:20:in `block in call'
activesupport (4.2.0) lib/active_support/tagged_logging.rb:68:in `block in tagged'
activesupport (4.2.0) lib/active_support/tagged_logging.rb:26:in `tagged'
activesupport (4.2.0) lib/active_support/tagged_logging.rb:68:in `tagged'
railties (4.2.0) lib/rails/rack/logger.rb:20:in `call'
actionpack (4.2.0) lib/action_dispatch/middleware/request_id.rb:21:in `call'
rack (1.6.0) lib/rack/methodoverride.rb:22:in `call'
rack (1.6.0) lib/rack/runtime.rb:18:in `call'
activesupport (4.2.0) lib/active_support/cache/strategy/local_cache_middleware.rb:28:in `call'
rack (1.6.0) lib/rack/lock.rb:17:in `call'
actionpack (4.2.0) lib/action_dispatch/middleware/static.rb:113:in `call'
rack (1.6.0) lib/rack/sendfile.rb:113:in `call'
railties (4.2.0) lib/rails/engine.rb:518:in `call'
railties (4.2.0) lib/rails/application.rb:164:in `call'
rack (1.6.0) lib/rack/lock.rb:17:in `call'
rack (1.6.0) lib/rack/content_length.rb:15:in `call'
rack (1.6.0) lib/rack/handler/webrick.rb:89:in `service'
/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/webrick/httpserver.rb:138:in `service'
/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/webrick/httpserver.rb:94:in `run'
/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/webrick/server.rb:295:in `block in start_thread'
我的赌注模型:
class Bet < ActiveRecord::Base
has_many :picks, dependent: :destroy
accepts_nested_attributes_for :picks
validates :odds, presence: true, numericality: true # { only_integer: true }
validates :time_completed, presence: true
end
我的选择型号:
class Pick < ActiveRecord::Base
belongs_to :bet
validates :team, presence: true #, length: { minimum: 1 }
validates :sport, presence: true, inclusion: { :in => ['Basketbal', 'Ice Hockey'] }
validates :league, presence: true, inclusion: { :in => %w( NBA NHL ) }
end
您是否在控制器中定义了 @bet
变量?如果是这样,请将您的 form_for
更改为 form_for @bet
。您的投注模型中还需要 accepts_nested_attributes_for :picks
。
请尝试一下,希望对您有所帮助
<% f.fields_for :picks do |pick_form| %>
<%= render :partial => '/picks/new', :f => pick_form %>
<% end %>