小编use*_*400的帖子

Rails 4:fields_for中的fields_for

我正在学习RoR,我正在尝试找到如何使用has_one模型在另一个中设置fields_for:

class Child < ActiveRecord::Base
    belongs_to :father
    accepts_nested_attributes_for :father
end

class Father < ActiveRecord::Base
    has_one :child
    belongs_to :grandfather
    accepts_nested_attributes_for :grandfather
end


class Grandfather < ActiveRecord::Base
    has_one :father
end
Run Code Online (Sandbox Code Playgroud)

我在Railscasts上使用嵌套模型表单第1部分来获取这些:在children_controller.rb中:

  def new
    @child = Child.new
    father=@child.build_father
    father.build_grandfather
  end

def child_params
      params.require(:child).permit(:name, father_attributes:[:name], grandfather_attributes:[:name])
    end
Run Code Online (Sandbox Code Playgroud)

我的形式:

<%= form_for(@child) do |f| %>
  <div class="field">
    <%= f.label :name %><br>
    <%= f.text_field :name %>
  </div>
  mother:<br>
  <%= f.fields_for :father do |ff| %>
    <%= ff.label :name %>
    <%= ff.text_field :name %><br>
      grand mother:<br>
      <%= f.fields_for :grandfather …
Run Code Online (Sandbox Code Playgroud)

ruby-on-rails form-for fields-for nested-form-for ruby-on-rails-4

15
推荐指数
1
解决办法
2万
查看次数

非常慢:ActiveRecord :: QueryCache#调用

我在heroku上有一个应用程序,在Puma上运行:

workers 2
threads_count 3
pool 5
Run Code Online (Sandbox Code Playgroud)

看起来有些请求卡在中间件中,它使应用程序非常慢(非常!).我见过其他人关于这个问题的线索,但到目前为止还没有解决方案.

如果您有任何提示,请告诉我.

aactiverecord_querycache_1 !

aactiverecord_querycache_2 !

activerecord rack heroku query-cache ruby-on-rails-4

12
推荐指数
2
解决办法
3873
查看次数