Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/59.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 如何在每个具有dashboard元素的页面上呈现新帐户对象的表单?_Ruby On Rails_Ruby On Rails 3 - Fatal编程技术网

Ruby on rails 如何在每个具有dashboard元素的页面上呈现新帐户对象的表单?

Ruby on rails 如何在每个具有dashboard元素的页面上呈现新帐户对象的表单?,ruby-on-rails,ruby-on-rails-3,Ruby On Rails,Ruby On Rails 3,我有一个表单,我想在每个包含部分仪表板的页面上呈现该表单: 帐户/新.slim #addAccount-modal.modal.hide.fade style="display: none;" h5 Create a New Account = form_for @account do |f| p Name: = f.text_field :name, value: "New Account" = f.submit "Create Account", clas

我有一个表单,我想在每个包含部分仪表板的页面上呈现该表单:

帐户/新.slim

#addAccount-modal.modal.hide.fade style="display: none;"
  h5 Create a New Account
  = form_for @account do |f|
    p Name: 
    = f.text_field :name, value: "New Account"

    = f.submit "Create Account", class: "btn"
_仪表板。苗条

.col-md-2
  ul.nav.nav-stacked#dashboard-nav
    li
      a href="#" Report
      a href="#" Accounts

      a data-toggle="modal" href="#addAccount-modal" + Add
=render "accounts/new"
问题是我没有在每个页面上实例化
@帐户。我目前只有在我的
Accounts#new
方法中才有它,所以除了这个之外,它每隔一页都会被破坏,因为表单的@account是nil


是否有一种简单的方法来确保每个页面上都实例化了
@account
,或者我必须手动将其添加到每个需要它的页面上?

您只需使用
account即可。
表单中的新

form_for Account.new do |f|