我希望能够做到这样的事情
rails_admin do
partial "custom_view", variable: my_variable
end
Rails_admin没有抱怨,但是模型变量在部分
内部无法识别我尝试了一些其他语法,例如:partial "custom_view", :variable => my_variable
或partial "custom_view", :locales { :variable => my_variable }
,但没有运气......
任何线索如何实现这一目标?
谢谢!
答案 0 :(得分:1)
今天有同样的问题。我在这里使用文档https://github.com/sferik/rails_admin/wiki/Railsadmin-DSL
config.model YourModel do
edit do
field :field_name do
def render
bindings[:view].render :partial => 'rails_admin/main/name_of_partial', :locals => {:field => self, :form => bindings[:form], variable: my_variable}
end
end
end
end
并将您的部分视图置于/ rails_admin / main / name_of_partial.html.erb
答案 1 :(得分:1)
在前面的评论的帮助下,我设法使用这种代码的部分:
show do
configure :candidacy do
pretty_value do
bindings[:view].render({
partial: "rails_admin/custom_partials/project_candidacy",
locals: {candidacy: value}
).html_safe
end
end
end
重要的是在渲染部分后不要忘记 .html_safe
答案 2 :(得分:0)
尝试render partial: "custom_view", locals: { variable: my_variable }
答案 3 :(得分:0)
你没有提供足够的信息,但上面的答案很接近。对于一个变量,您可以执行类似
的操作render partial: "foo/custom_view", admin: @user
或
render partial: "foo/custom_view", locals: { admin: @user }
render partial: "foo/custom_view", object: @user, as: 'admin'
除非它是一个集合,否则你会
render partial: "foo/custom_view", things: @things
或
render partial: "foo/custom_view", locals: { things: @things }
render partial: "foo/custom_view", collection: @things, as: 'things'