在哪里放置 rails_admin 视图的部分 [英] where to put partials for rails_admin views

查看:60
本文介绍了在哪里放置 rails_admin 视图的部分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用部分来自定义 rails_admin 中的编辑视图.在 config/initializers/rails_admin.rb 我有:

I am trying to use a partial to customize my edit view in rails_admin. In config/initializers/rails_admin.rb I have:

RailsAdmin.config do |config|

  config.model 'Album' do
    edit do
      field :promotion do
        partial :hello_world
      end
    end
  end

end

我还尝试了可以​​在 rails_admin wiki 上找到的其他语法:

I have also tried the other syntax that can be found on the rails_admin wiki:

RailsAdmin.config do |config|

  config.model 'Album' do
    edit do
      field :promotion do
         def render
            bindings[:view].render :partial => carrierwave.to_s, :locals => {:field => self, :form => bindings[:form]}
         end
      end
    end
  end

end

我在 app/views/rails_admin/main/_hello_world.html.erb 中找到我的部分内容:

I am locating my partial at app/views/rails_admin/main/_hello_world.html.erb with the content:

<h1>Hello World!</h1>

重新启动我的服务器后,除了一个空的促销"字段外,编辑视图中没有任何显示.

After restarting my server nothing shows up in the edit view except for an empty 'promotion' field.

Rails_admin 对此有一个 github 问题.讨论似乎没有结果,在任何人确认该解决方案对他们有用之前,问题就已结束.可以在此处查看该问题:

Rails_admin had a github issue for this. The discussion seemed inconclusive and the issue was closed before anyone confirmed that the solution worked for them. The issue can be viewed here:

https://github.com/sferik/rails_admin/issues/787

版主为问题创建规范,然后将其关闭.可以在此文件的最底部查看规范:

The moderator creates a spec for the issue and then closes it. The spec can be viewed at the very bottom of this file:

https://github.com/sferik/rails_admin/blob/59da00303ca2162089b7dd7653a2f19494fb74b4/spec/unit/config/fields/base_spec.rb

我对规范的担忧是它没有测试 rails_admin 在哪里寻找部分.根据 rails_admin wiki 部分应该是位置在 app/views/rails_admin/main/

My concern with the spec is that it does not test where rails_admin looks for the partial. According to the rails_admin wiki partials should be location in app/views/rails_admin/main/

请帮助我理解我做错了什么,或者至少请向我保证 rails_admin 在这里仍然没有问题.我使用的是 Rails 4 和 Ruby 2.0.0

Please help me understand what I'm doing wrong or, at least, please assure me that rails_admin does not still have an issue here. I'm using Rails 4 and Ruby 2.0.0

推荐答案

查看 rails-admin 文档中,似乎部分在两个示例中都被渲染为字符串,而 不是 作为符号.尝试将您的代码更改为以下内容:

Looking at the syntax provided in rails-admin documentation, it appears like the partial is being rendered as a string in both examples, and not as a symbol. Try changing your code to the following:

RailsAdmin.config do |config|

  config.model 'Album' do
    edit do
      field :promotion do
        partial "hello_world"
      end
    end
  end

end

如果这不能解决问题,我会推荐 gem jazz-hands.这是一个内置了 pry-stack-explorer 的调试包.我将它与 pry-stack-explorer 一起使用code>binding.pry 和 raise 以调试流程或进入方法并查看发生了什么.

If that doesn't fix the problem, I would recommend the gem jazz-hands. It's a debugging package that has pry-stack-explorer built in. I use this in tandem with binding.pry and raise in order to debug flow or to step into methods and see what's going on.

我敢打赌,您将能够找出 gem 的哪一部分实际渲染了视图.在使用 gems 时,我发现深入研究各自的代码库以找出幕后发生的事情是很常见的.祝你好运!

I bet you'll be able to track down what part of the gem is actually rendering the view. When using gems, I've found it pretty common to dig into the respective code base to figure out what's going on behind the scenes. Good luck!

这篇关于在哪里放置 rails_admin 视图的部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆