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 如何使用两个不同的simple_form.rb初始值设定项文件? 问题_Ruby On Rails_Simple Form_Spree - Fatal编程技术网

Ruby on rails 如何使用两个不同的simple_form.rb初始值设定项文件? 问题

Ruby on rails 如何使用两个不同的simple_form.rb初始值设定项文件? 问题,ruby-on-rails,simple-form,spree,Ruby On Rails,Simple Form,Spree,这是一个简单的问题,我环顾了spree论坛、plataforma tec论坛等,但没有成功 我们希望使用两个单独的简单表单配置,一个用于主应用程序,另一个用于安装在特定url上的spree引擎存储 更详细的解释 目前,我们正在使用spree引擎开发一个应用程序。这意味着spree引擎安装在特定的url上,并通过访问mysite.com/store激活 现在,在主应用程序上,我们使用的资产与spree store不同。我们最初的simple_form.rb初始值设定项是专门为这些资产创建的 这就是

这是一个简单的问题,我环顾了spree论坛、plataforma tec论坛等,但没有成功

我们希望使用两个单独的简单表单配置,一个用于主应用程序,另一个用于安装在特定url上的spree引擎存储

更详细的解释 目前,我们正在使用spree引擎开发一个应用程序。这意味着spree引擎安装在特定的url上,并通过访问mysite.com/store激活

现在,在主应用程序上,我们使用的资产与spree store不同。我们最初的simple_form.rb初始值设定项是专门为这些资产创建的

这就是它变得有趣的地方

在spree引擎中,我们还使用simple_form开发了一个新表单。它工作得很好,但它使用的是主应用程序的simple_form.rb文件,它使用主应用程序的css标记和标记

我们需要修改simple_form.rb文件以实际使用spree模板的css,以便正确显示内容

可能的解决方案? 理想情况下,我们应该为spree引擎和主应用程序分别提供一个简单的_form.rb文件,但我还没有想出一个简单的方法来实现这一点


我的另一个想法是在simple_form.rb文件中添加某种条件,以便在主应用程序上加载一组选项,在spree store中加载另一组选项。。。也许是检查url?

好的,所以很明显,对于简单表单,如何进行单独的配置是非常明显的

所有内容都进入一个简单的\u form.rb初始值设定项。唯一改变的是config.wrapper

SimpleForm.setup do |config|
  # Wrappers are used by the form builder to generate a
  # complete input. You can remove any component from the
  # wrapper, change the order or even add your own to the
  # stack. The options given below are used to wrap the
  # whole input.
  config.wrappers :default, :class => :input do |b|
    # config goes here
  end

  config.wrappers :special, :class => input do |b|
    # special config goes here
  end

  config.default_wrapper = :default
end
然后在您的代码中,如果您想使用
:special
包装器,只需像这样写入您的输入

f.input :name, :wrapper => :special
你可以在这里找到更多信息


尝试使用URL方法,但不起作用,因为初始化器仅在应用程序启动时运行,而不是在启动期间。遗憾的是,自定义包装器似乎仅用于自定义输入配置(通过
b.use
b.optional
)。它们不支持根级别的配置选项,如
config.button\u类
config.boolean\u样式
,等等。