小编tar*_*rky的帖子

如何更改group_vars和host_vars的路径?

我们可以通过修改roles_pathin 来改变角色的路径ansible.cfg.但该文件似乎没有提及任何改变路径group_varshost_vars.

我该如何改变这些路径?

我将与ansible相关的文件与rails app repsitory集成.我想在单个目录下收集角色和vars目录,但是将hosts文件和ansible.cfg保留在顶层目录中,这样顶层目录很容易看到,我仍然可以ansible-playbook在顶层目录中运行而无需移动到深层目录.

提前致谢.

ansible

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

如何使用多个source_type?

我的模型目前在下面.

user.rb

class User < ActiveRecord::Base
  has_many :authentications
end
Run Code Online (Sandbox Code Playgroud)

authentication.rb

class Authentication < ActiveRecord::Base
  belongs_to :user
  belongs_to :social, polymorphic: true 
end
Run Code Online (Sandbox Code Playgroud)

facebook.rb

class Facebook < ActiveRecord::Base
  has_one :authentication, as: :social
end
Run Code Online (Sandbox Code Playgroud)

twitter.rb

class Twitter < ActiveRecord::Base
  has_one :authentication, as: :social
end
Run Code Online (Sandbox Code Playgroud)

现在感谢多态关联,我可以访问对象中的任何一个TwitterFacebookAuthentication对象,如下所示:

 authentication.social
Run Code Online (Sandbox Code Playgroud)

然后我想直接从对象访问TwitterFacebook对象,User使用:through选项来调用单个方法,如下所示:

user.socials
Run Code Online (Sandbox Code Playgroud)

所以我尝试修改User模型,如下面的两个样本:

SAMPLE1

class User < ActiveRecord::Base
  has_many :authentications
  has_many :socials, through: :authentications, source: :social, source_type: "Twitter"
  has_many :socials, through: :authentications, …
Run Code Online (Sandbox Code Playgroud)

ruby-on-rails-4

9
推荐指数
1
解决办法
888
查看次数

标签 统计

ansible ×1

ruby-on-rails-4 ×1